getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.79k stars 1.53k forks source link

Attempted import error `_optionalChain` and `_nullishCoalesce` on `@sentry/nextjs` 7.114.0 #11961

Open 0x33dm opened 2 months ago

0x33dm commented 2 months ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.114.0

Framework Version

14.2.3

Link to Sentry event

No response

SDK Setup

sentry.client.config.ts

import * as Sentry from '@sentry/nextjs'

const release =
  process.env.VERCEL_GITHUB_COMMIT_SHA ||
  process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA

console.log('Sentry.init with release:', release)

Sentry.init({
  release,
  dsn: 'xxx',
  tracesSampleRate: 1,
  debug: false,
  replaysOnErrorSampleRate: 1.0,
  replaysSessionSampleRate: 0.1,
  integrations: [
    Sentry.replayIntegration({
      maskAllText: false,
      blockAllMedia: false
    }),
    Sentry.captureConsoleIntegration(),
    Sentry.sessionTimingIntegration()
  ],
  enabled:
    process.env.NEXT_PUBLIC_VERCEL_ENV === 'production' ||
    process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview'
})
\\\\

# ag sentry/
````bash
apps/dapp/src/app/global-error.tsx
3:import * as Sentry from '@sentry/nextjs'

apps/dapp/sentry.server.config.ts
1:import * as Sentry from '@sentry/nextjs'

apps/dapp/sentry.edge.config.ts
1:import * as Sentry from '@sentry/nextjs'

apps/dapp/sentry.client.config.ts
1:import * as Sentry from '@sentry/nextjs'

apps/dapp/package.json
21:    "@sentry/nextjs": "^7.114.0",

pnpm-lock.yaml
102:      '@sentry/nextjs':
2150:  '@sentry/browser@7.114.0':
2154:  '@sentry/cli@1.77.3':
2159:  '@sentry/core@7.114.0':
2163:  '@sentry/integrations@7.114.0':
2167:  '@sentry/nextjs@7.114.0':
2178:  '@sentry/node@7.114.0':
2182:  '@sentry/react@7.114.0':
2188:  '@sentry/replay@7.114.0':
2192:  '@sentry/types@7.114.0':
2196:  '@sentry/utils@7.114.0':
2200:  '@sentry/vercel-edge@7.114.0':
2204:  '@sentry/webpack-plugin@1.21.0':
9610:      '@sentry/core': 7.114.0
9611:      '@sentry/types': 7.114.0
9612:      '@sentry/utils': 7.114.0
9616:      '@sentry/core': 7.114.0
9617:      '@sentry/replay': 7.114.0
9618:      '@sentry/types': 7.114.0
9619:      '@sentry/utils': 7.114.0
9623:      '@sentry/core': 7.114.0
9624:      '@sentry/types': 7.114.0
9625:      '@sentry/utils': 7.114.0
9627:  '@sentry/browser@7.114.0':
9632:      '@sentry/core': 7.114.0
9633:      '@sentry/integrations': 7.114.0
9634:      '@sentry/replay': 7.114.0
9635:      '@sentry/types': 7.114.0
9636:      '@sentry/utils': 7.114.0
9638:  '@sentry/cli@1.77.3':
9650:  '@sentry/core@7.114.0':
9652:      '@sentry/types': 7.114.0
9653:      '@sentry/utils': 7.114.0
9655:  '@sentry/integrations@7.114.0':
9657:      '@sentry/core': 7.114.0
9658:      '@sentry/types': 7.114.0
9659:      '@sentry/utils': 7.114.0
9662:  '@sentry/nextjs@7.114.0(next@14.2.3)(react@18.3.1)(webpack@5.91.0)':
9665:      '@sentry/core': 7.114.0
9666:      '@sentry/integrations': 7.114.0
9667:      '@sentry/node': 7.114.0
9668:      '@sentry/react': 7.114.0(react@18.3.1)
9669:      '@sentry/types': 7.114.0
9670:      '@sentry/utils': 7.114.0
9671:      '@sentry/vercel-edge': 7.114.0
9672:      '@sentry/webpack-plugin': 1.21.0
9684:  '@sentry/node@7.114.0':
9687:      '@sentry/core': 7.114.0
9688:      '@sentry/integrations': 7.114.0
9689:      '@sentry/types': 7.114.0
9690:      '@sentry/utils': 7.114.0
9692:  '@sentry/react@7.114.0(react@18.3.1)':
9694:      '@sentry/browser': 7.114.0
9695:      '@sentry/core': 7.114.0
9696:      '@sentry/types': 7.114.0
9697:      '@sentry/utils': 7.114.0
9701:  '@sentry/replay@7.114.0':
9704:      '@sentry/core': 7.114.0
9705:      '@sentry/types': 7.114.0
9706:      '@sentry/utils': 7.114.0
9708:  '@sentry/types@7.114.0': {}
9710:  '@sentry/utils@7.114.0':
9712:      '@sentry/types': 7.114.0
9714:  '@sentry/vercel-edge@7.114.0':
9717:      '@sentry/core': 7.114.0
9718:      '@sentry/integrations': 7.114.0
9719:      '@sentry/types': 7.114.0
9720:      '@sentry/utils': 7.114.0
9722:  '@sentry/webpack-plugin@1.21.0':
9724:      '@sentry/cli': 1.77.3

apps/dapp/next.config.js
2:const { withSentryConfig } = require('@sentry/nextjs')
38:    // https://github.com/getsentry/sentry-webpack-plugin#options

Steps to Reproduce

  1. pnpm dev
  2. go to localhost:3000

Running:

Expected Result

No console logs on the server side

Actual Result

Import trace for requested module:
./src/app/page.tsx

./src/app/page.tsx
Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain').

Import trace for requested module:
./src/app/page.tsx

./src/app/page.tsx
Attempted import error: '_nullishCoalesce' is not exported from '@sentry/utils' (imported as '_nullishCoalesce').
lforst commented 2 months ago

arch btw πŸ˜‚

would you mind checking your dependency lockfile for any versions of @sentry/* dependencies that may not be aligned? The only exception to this should be @sentry/webpack-plugin.

Otherwise, until we have figured this out, you could try migrating to the next major version 8.0.0-rc.2 of the SDK. That probably fixes it right away. Migration guide is here: https://docs.sentry.io/platforms/javascript/guides/nextjs/migration/v7-to-v8/

0x33dm commented 2 months ago

arch btw πŸ˜‚

πŸ˜‚πŸ˜‚πŸ˜‚ πŸ’ͺ

would you mind checking your dependency lockfile for any versions of @sentry/* dependencies that may not be aligned? The only exception to this should be @sentry/webpack-plugin.

I posted all the sentry lines on my lock file on my post?

Doesn't seem to be unaligned, but i will triple check!

Otherwise, until we have figured this out, you could try migrating to the next major version 8.0.0-rc.2 of the SDK. That probably fixes it right away. Migration guide is here: https://docs.sentry.io/platforms/javascript/guides/nextjs/migration/v7-to-v8/

Yes, will do that and get back to you. This is ideal

lforst commented 2 months ago

I posted all the sentry lines on my lock file on my post?

Ah I didn't scroll down in the code block. Sorry.

0x33dm commented 2 months ago

I posted all the sentry lines on my lock file on my post?

Ah I didn't scroll down in the code block. Sorry.

i run npx @sentry/migr8@latest and it did no changes to my code.

I'm currently running 7.114, I was expecting it to update my package.json to the latest 8.x release?

Since it didn't do it, I'm guessing I'm supposed to run the npm install for 8.x myself and then do all the other steps on the page you linked, is that assumption correct?

lforst commented 2 months ago

@sentry/migr8 unfortunately doesn't take care of everything for you. Especially @sentry/nextjs specific changes. If you do not have any special sentry code except for the basic setup you only have to follow the docs I shared! Generally when migr8 doesn't do any changes in your code it means that you don't have anything custom.

bigvisionmalachibazar commented 1 month ago

I'm having the same issue. I did a fresh install of Sentry with npx @sentry/wizard@latest -i nextjs and am getting this:

./app/layout.tsx
Attempted import error: '_nullishCoalesce' is not exported from '@sentry/utils' (imported as '_nullishCoalesce').

Import trace for requested module:
./app/layout.tsx

./app/layout.tsx
Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain').

Import trace for requested module:
./app/layout.tsx

./app/layout.tsx
Attempted import error: '_nullishCoalesce' is not exported from '@sentry/utils' (imported as '_nullishCoalesce').

Import trace for requested module:
./app/layout.tsx

./app/layout.tsx
Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain').

Import trace for requested module:
./app/layout.tsx

./app/layout.tsx
Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain').

Import trace for requested module:
./app/layout.tsx

I'm using @sentry/nextjs@8.9.2 with next@14.2.4

lforst commented 1 month ago

@bigvisionmalachibazar please wipe your node_modules, wipe your .next folder, reinstall dependencies and check that you do not have @sentry/* dependencies on different versions in your lockfile. Thanks!

0x33dm commented 1 month ago

I can report that i don't get the error on ubuntu. weirdly.

before on arch i tried cleaning everything and i still got the error again and again even though i checked all the versions, etcs..

maybe @bigvisionmalachibazar could add his OS as part of the report?

lforst commented 1 month ago

This should not be an issue anymore on version 8 of the SDK.

alenoir commented 1 month ago

I'm using @sentry/nextjs@8.9.2 with next@14.2.4

Same version, same logs

lforst commented 1 month ago

If anybody would be able to provide a simple reproduction we can take a deeper look.

bigvisionmalachibazar commented 1 month ago

@bigvisionmalachibazar please wipe your node_modules, wipe your .next folder, reinstall dependencies and check that you do not have @sentry/* dependencies on different versions in your lockfile. Thanks!

This fixed it for me! I am running PopOS.

annez commented 3 weeks ago

I also get this - brand new install of everything. There is my OS below.

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:43 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 18.19.0
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.2.4 // Latest available version is detected (14.2.4).
  eslint-config-next: 14.2.4
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A
lforst commented 3 weeks ago

@annez please open a new issue with reproduction thanks!