Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain') #9534

Closed
3 tasks done
tmwBuidls opened this issue Nov 10, 2023 · 10 comments
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@tmwBuidls
Copy link

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

Framework Version

Next 14.0.2

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

  1. Follow the default install using the wizard for nextjs
  2. Load sentry example page or any other page
  3. Events still being captured but logs spammed with Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain')

Other things to note:

  • Using Node Version 20.6.0
  • When I downgraded the error only seems to start appearing from 7.78.0

Expected Result

Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain') is not thrown/ logged

Actual Result

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/sentry-example-page/page.jsx
Attempted import error: '_optionalChain' is not exported from '@sentry/utils' (imported as '_optionalChain').
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 10, 2023
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Nov 10, 2023
@lforst
Copy link
Member

lforst commented Nov 10, 2023

Hi, can you share a reproduction example? Thanks!

@mydea
Copy link
Member

mydea commented Nov 13, 2023

Also, could you check and make sure that all versions of @sentry/xxx packages in your lockfile have been updated to 7.80.0, and you don't have any older versions remaining in there - this can also lead to these kind of problems!

@finsterwalder
Copy link

finsterwalder commented Nov 13, 2023

We had a similar issue upgrading from an older version to sentry to 7.80.0.
Our error was: TypeError: _optionalChain is not a function
Maybe old versions of sentry somehow collided?
We include sentry-expo, sentry/react-native and sentry/nextjs in our project and they all drag other versions of sentry/core along (7.69.0, 7.76.0 and 7.80.0).
But deleting the node_modules folder and rebuilding solved our issue for some reason... 🤔

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 13, 2023
@mydea
Copy link
Member

mydea commented Nov 13, 2023

We had a similar issue upgrading from an older version to sentry to 7.80.0. Our error was: TypeError: _optionalChain is not a function Maybe old versions of sentry somehow collided? We include sentry-expo, sentry/react-native and sentry/nextjs in our project and they all drag other versions of sentry/core along (7.69.0, 7.76.0 and 7.80.0). But deleting the node_modules folder and rebuilding solved our issue for some reason... 🤔

Hey,

yeah, that is most probably the reason then. This method was introduced in v7.80.0 so if for some reason you are pulling in e.g. 7.79.0 of @sentry/utils, it will fail. We have some ideas on how to help detect these kind of issues, but sadly this is always a bit tricky to track down.

@finsterwalder
Copy link

First of all you could release a new version of sentry/react-native, because that will depend on 7.80.0 as well, reducing version clutter. And even more so, since version before 7.77 have a security flaw.
Then then it would be even better to also upgrade sentry-expo. But that seams to be governed by Expo?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 13, 2023
@lforst
Copy link
Member

lforst commented Nov 13, 2023

@finsterwalder I don't think this one is on us tbh. In this case, package managers and bundlers are the things that are complicating things. We strictly define all of our dependencies - what ends up being bundled or used by your app is out of our control.

@finsterwalder
Copy link

Yes sure. I'm just hinting at the transitive dependencies of other libraries, not of my code.
sentry/react-native seams to be under "your" control. You meaning sentry. :-)
And the current main branch already has upgraded the dependency to sentry/core 7.80.0, which is good. It would be great to release that version soon.
As I said, I don't know if you are involved in sentry-expo directly or indirectly. But of course it would be great if that project would also upgrade to sentry/core 7.80.0
And overall, my code compiles and works currently.

@lforst
Copy link
Member

lforst commented Nov 13, 2023

@tmwBuidls Can you try what @finsterwalder did to resolve the issue? I recommend removing your .next and node_modules folders and doing a clean install and build.

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 Nov 13, 2023
@tmwBuidls
Copy link
Author

You're right, this fixed it. One thing to note, and this is probably a bundler problem not Sentry, but the issue was arising I think as we're using a monorepo with turbo and pnpm and one of the apps had not been upgraded so for whatever reason the upgraded app was using utils from the older package.

@0x33dm
Copy link

0x33dm commented May 9, 2024

Since this issue is closed and has an older version of the SDK I have created a new issue.

#11961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
Archived in project
Development

No branches or pull requests

5 participants