vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
423 stars 26 forks source link

Jest: Cannot find module @vercel/analytics/react from src/pages/_app.tsx #22

Closed bitabs closed 1 year ago

bitabs commented 1 year ago

Hi there,

I'm using Blitz, and Jest test is failing:

Screenshot 2022-11-23 at 18 48 13 Screenshot 2022-11-23 at 18 48 28

Jest

Screenshot 2022-11-23 at 18 49 23
dglsparsons commented 1 year ago

Hey @bitabs, thanks for raising this. We'll get investigating! I suspect it's something to do with how the module is packaged...

Are you just using a blitzjs starter? Is there a minimal repro you can share? I'm not overly familiar with blitz :D

bitabs commented 1 year ago

Hya 👋🏻 @dglsparsons - Yes, It's a Blitz starter indeed. Can you please try the starter?

dglsparsons commented 1 year ago

Hey @bitabs! Sorry, but I'm struggling to reproduce this - I'm being frustratingly blocked on this Blitz issue which means I'm struggling to get any tests to work at all in Blitz.

I was, however, able to set up a brand new NextJS project based on the NextJS Jest Example. Adding Analytics to this in either the _app.tsx file, or in a specific page gave me no issues at all though - and worked exactly as you'd expect.

Screenshot 2022-11-28 at 11 25 19

It seems like the issue is with the Blitz jest config because of this. However, since I'm unable to reproduce I can't confirm this.

Sorry to ask again, but I don't suppose you are able to share any reproduction?

dillondotzip commented 1 year ago

Hey just here to add some context. We had some issues with jest & some types. There is a PR open currently to scrap jest completely and move to vitest https://github.com/blitz-js/blitz/pull/3985

bitabs commented 1 year ago

@dglsparsons I share your frustration, unfortunately. 😞 It looks like something very specific to Blitz. @dillonraphael Thanks for jumping in and adding some context 🙇.

I guess I'll close this ticket for the time being 🙏🏻

wowczarczyk commented 1 year ago

For me it was a matter of adding this to "jest" config in package.json:

"jest": {
    "moduleNameMapper": {
      "@vercel/analytics/react": "identity-obj-proxy"
    }
  },