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

Can't resolve 'react/jsx-runtime' in xxx/node_modules/@sentry/react/esm #12608

Closed
3 tasks done
htCaoHaitao opened this issue Jun 24, 2024 · 25 comments · Fixed by #12740 or #12775
Closed
3 tasks done

Can't resolve 'react/jsx-runtime' in xxx/node_modules/@sentry/react/esm #12608

htCaoHaitao opened this issue Jun 24, 2024 · 25 comments · Fixed by #12740 or #12775
Assignees
Labels
Package: browser Issues related to the Sentry Browser SDK Type: Bug

Comments

@htCaoHaitao
Copy link

htCaoHaitao commented Jun 24, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

8.5.0

Framework Version

React: 17.0.2

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

1、update sentry sdk version

yarn upgrade @sentry/[email protected] @sentry/[email protected]

2、run project in local

yarn start

Expected Result

The project run with no error as shown below :
image

Actual Result

image
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jun 24, 2024
@github-actions github-actions bot added the Package: browser Issues related to the Sentry Browser SDK label Jun 24, 2024
@lforst
Copy link
Member

lforst commented Jun 24, 2024

Hi, would you mind sharing a small reproduction example we could clone to check this error out? It is usually quite hard to troubleshoot build errors without having access to the bigger picture because there is usually so much configuration involved. Thanks!

@webdevian
Copy link

Getting same error on @sentry/[email protected] and on @sentry/[email protected] when I tried last week. With [email protected]. Node v20.6.1

Module not found: Error: Can't resolve 'react/jsx-runtime' in 'node_modules/@sentry/react/esm'
Did you mean 'jsx-runtime.js'?
BREAKING CHANGE: The request 'react/jsx-runtime' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

The error seems to be referring to
import { jsx } from 'react/jsx-runtime'; in node_modules/@sentry/react/esm/errorboundary.js
and
{"type":"module","sideEffects":false} in node_modules/@sentry/react/esm/package.json

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Jun 24, 2024
@baw
Copy link

baw commented Jun 24, 2024

We have been having this issue in @sentry/react in every version since version 8.5.0

@lforst
Copy link
Member

lforst commented Jun 25, 2024

Hi @webdevian and @baw! It would be amazing if you could share a small reproduction example where this is happening.

@pieterbeulque
Copy link

+1 for @baw, it's hard to set up a minimal reproduction though. It looks like it might be related with us using React 17 and React Router 6, but I'm not 100% sure.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jun 26, 2024
@baw
Copy link

baw commented Jun 26, 2024

We've seen this in one app when it was running React 16 and it continues after it was upgraded to React 17. I don't think it's a React issue.

I only see this in one of our apps and we have other apps running the latest version of @sentry/react without any issues.

I'd rather spend the time fixing the issue in our app and then get back to you than make a small reproduction example.

@AbhiPrasad
Copy link
Member

Due to the variety of permutations of how you can set up a react app, we really need a reproduction to dive into this. Even just sharing your bundler config and showing how you are importing Sentry would be a great help!

@marcospachecows
Copy link

I've been seeing the same error after I upgraded @sentry/react from ^7.114.0 to ^8.12.0 using the npx @sentry/migr8@latest command. My React version is ^16.6.0:

{
    "dependencies": {
        ...
        "react": "^16.6.0",
        "react-dom": "^16.6.0",
        "react-router": "^5.2.1",
        "react-router-dom": "^5.3.0",
        "@sentry/react": "^8.12.0"
        ...
    }
}
Screenshot 2024-06-26 at 1 04 20 PM

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jun 26, 2024
@AbhiPrasad
Copy link
Member

AbhiPrasad commented Jun 26, 2024

Our peer deps state we only support 16.14.0 or higher:

"react": "^16.14.0 || 17.x || 18.x || 19.x"

Could you upgrade your react version to 16.14.0 and check if the error still exists?

@marcosdiasdev
Copy link

I've got the same error message while trying to build an application with "react": "^17.0.2" and "@sentry/react": "^8.13.0". Downgrading Sentry to "@sentry/react": "^7.118.0" fixed it.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 1, 2024
@lforst
Copy link
Member

lforst commented Jul 2, 2024

@marcosdiasdev I would like to reiterate, this issue needs reproduction. To look into this further, we need a way to reproduce this error. Please provide a stackblitz or github repo, or something similar. Thanks!

@pieterbeulque
Copy link

pieterbeulque commented Jul 3, 2024

@lforst here you go: https://github.com/pieterbeulque/getsentry-sentry-javascript-12608/commits/main/

Run npm run build and you'll see that 8.4.0 works, 8.5.0 onwards fails.

Given the error I assume it's a combination of Webpack + Babel + React 17 + whatever changes you made going from 8.4 to 8.5. (I left some other React-adjacent packages in the dependencies but I think they may be irrelevant. Edit: removed)

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 3, 2024
@lforst lforst self-assigned this Jul 3, 2024
@lforst
Copy link
Member

lforst commented Jul 3, 2024

@pieterbeulque awesome thanks! I'll take a look.

@pieterbeulque
Copy link

That was fast, thanks @lforst.

@nocive
Copy link

nocive commented Jul 4, 2024

Still running into the same issue with 8.14 (vitest).

Looking at the source code, it doesn't look like the fix had any actual effect on the resulting code since I still see the incorrect import being used.

@alexandersorokin
Copy link

alexandersorokin commented Jul 4, 2024

I have encountered such an issue several times with other packages.

Upgrading to react@18 should fix the issue. Also configuring a bundler alias can fix the issue. Also not using esm can fix the issue.

But I have found no way to fix the issue on package side (like @sentry/react) for both react@17 and react@18.
react@17 doesn't have an exports field in package.json and requires react/jsx-runtime.js (with extension).
react@18 does have the exports field in package.json and support react/jsx-runtime only without extension.

@pieterbeulque
Copy link

@lforst - As mentioned above, looks like the fix doesn't actually fix it. Updated the reproduction repo.

@lforst
Copy link
Member

lforst commented Jul 4, 2024

Update: We're gonna move back to the classic runtime because we discovered issues with a non-faulty fix. The "fix" we merged actually did nothing because I made a mistake while testing. This will cause warnings in React 19, maybe we can find a way to provide a separate package or submodule exports for the new runtime when React 19 ships stably.

@nocive
Copy link

nocive commented Jul 5, 2024

thanks for the fast fix & release guys, works now 🎉

andreiborza added a commit that referenced this issue Jul 5, 2024
Adds a react 17 test app so we can hopefully catch breaking react 17, as
we did recently
(#12608) with
#12204 and
#12740.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: browser Issues related to the Sentry Browser SDK Type: Bug
Projects
Archived in project