sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

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

Open 0x33dm opened this issue 1 year ago • 12 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

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/[email protected]':
2154:  '@sentry/[email protected]':
2159:  '@sentry/[email protected]':
2163:  '@sentry/[email protected]':
2167:  '@sentry/[email protected]':
2178:  '@sentry/[email protected]':
2182:  '@sentry/[email protected]':
2188:  '@sentry/[email protected]':
2192:  '@sentry/[email protected]':
2196:  '@sentry/[email protected]':
2200:  '@sentry/[email protected]':
2204:  '@sentry/[email protected]':
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/[email protected]':
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/[email protected]':
9650:  '@sentry/[email protected]':
9652:      '@sentry/types': 7.114.0
9653:      '@sentry/utils': 7.114.0
9655:  '@sentry/[email protected]':
9657:      '@sentry/core': 7.114.0
9658:      '@sentry/types': 7.114.0
9659:      '@sentry/utils': 7.114.0
9662:  '@sentry/[email protected]([email protected])([email protected])([email protected])':
9665:      '@sentry/core': 7.114.0
9666:      '@sentry/integrations': 7.114.0
9667:      '@sentry/node': 7.114.0
9668:      '@sentry/react': 7.114.0([email protected])
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/[email protected]':
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/[email protected]([email protected])':
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/[email protected]':
9704:      '@sentry/core': 7.114.0
9705:      '@sentry/types': 7.114.0
9706:      '@sentry/utils': 7.114.0
9708:  '@sentry/[email protected]': {}
9710:  '@sentry/[email protected]':
9712:      '@sentry/types': 7.114.0
9714:  '@sentry/[email protected]':
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/[email protected]':
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:

  • pnpm 9.0.6
  • arch linux ( why not brag a bit :rofl: )
  • "@sentry/nextjs": "^7.114.0"
  • all my @sentry/utils at the same version ( see ag above )
  • have cleaned and redone all the node_modules, .next, .turbo, .swc

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').

0x33dm avatar May 09 '24 07:05 0x33dm

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/

lforst avatar May 10 '24 08:05 lforst

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

0x33dm avatar May 10 '24 13:05 0x33dm

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

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

lforst avatar May 10 '24 14:05 lforst

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?

0x33dm avatar May 12 '24 19:05 0x33dm

@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.

lforst avatar May 14 '24 10:05 lforst

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/[email protected] with [email protected]

bigvisionmalachibazar avatar Jun 15 '24 13:06 bigvisionmalachibazar

@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!

lforst avatar Jun 19 '24 10:06 lforst

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?

0x33dm avatar Jun 19 '24 11:06 0x33dm

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

lforst avatar Jun 19 '24 11:06 lforst

I'm using @sentry/[email protected] with [email protected]

Same version, same logs

alenoir avatar Jun 19 '24 12:06 alenoir

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

lforst avatar Jun 19 '24 12:06 lforst

@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.

bigvisionmalachibazar avatar Jun 20 '24 12:06 bigvisionmalachibazar

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

annez avatar Jul 01 '24 12:07 annez

@annez please open a new issue with reproduction thanks!

lforst avatar Jul 01 '24 13:07 lforst

I was looking into this and I think the issue for me that @sentry/core wasn't installed with pnpm properly as a dependency of @sentry/nextjs. So I manually installed and it solved my issue.

I know this is not the best mitigation. I would like to wait for a patch from Sentry team to get this working smoothly with pnpm.

My other guess is that since I use _get from 'lodash/get' this _optionalChain and _nullishCoalesce get triggered. Here is the relevant code

OttlikG avatar Dec 03 '24 10:12 OttlikG

@OttlikG we have no patch planned. @sentry/core is already a dependency of @sentry/nextjs, meaning there is nothing more we can do.

If you have suggestions, let us know.

lforst avatar Dec 03 '24 11:12 lforst

@lforst with all due respect (I love Sentry!), I ran into the same issue that @OttlikG had, and like him, manually installing @sentry/core fixed it for me.

I note that I didn't install @sentry/nextjs manually; I used the wizard. Maybe that's why @sentry/core wasn't installed?

noahlt avatar Dec 06 '24 01:12 noahlt

@noahlt The wizard also simply does npm i @sentry/nextjs (or other package manager's equivalent). @sentry/core should be getting installed alongside.

What package manager are you using?

lforst avatar Dec 06 '24 08:12 lforst

Ran into the exact same issue after using the wizard , installing @sentry/core manually fixed it as well. I am using pnpm, on macos, in a turborepo.

wouter173 avatar Dec 19 '24 09:12 wouter173