`plugin-react`: Fails to bundle `@sentry/react` if `mode` is not `production`
See original GitHub issueDescribe the bug
I am using Vite in a project using @sentry/react, and when I vite build the project with a --mode other than production it fails with the message seen in the Logs section.
I’ve tried to use the exclude option to exclude /node_modules/ and various other paths but they did not make a difference.
This only happens with plugin-react included and using jsxRuntime: 'automatic'
Reproduction
https://github.com/BeeeQueue/vite-sentry-repro/actions/runs/2732156122
System Info
System:
OS: macOS 11.6.7
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 214.50 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.16.0 - ~/nvm-rust/shims/node
Yarn: 1.22.15 - ~/nvm-rust/shims/yarn
npm: 8.11.0 - ~/nvm-rust/shims/npm
Browsers:
Chrome: 103.0.5060.134
Firefox: 102.0
Safari: 15.5
npmPackages:
@vitejs/plugin-react: 2.0.0 => 2.0.0
vite: 3.0.2 => 3.0.2
Used Package Manager
pnpm
Logs
Click to expand!
[commonjs--resolver] /Users/ahaglund/projects/vite-sentry-repro/node_modules/.pnpm/@sentry+react@7.7.0_react@18.2.0/node_modules/@sentry/react/esm/profiler.js: Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config. (This is an error on an internal node. Probably an internal error. Location has been estimated.)
114 | var Wrapped = (props) => (
115 | React.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 133}}
> 116 | , React.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 134}} )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117 | )
118 | );
119 |
file: /Users/ahaglund/projects/vite-sentry-repro/node_modules/.pnpm/@sentry+react@7.7.0_react@18.2.0/node_modules/@sentry/react/esm/profiler.js
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:8
- Comments:6
Top Results From Across the Web
@sentry/react | Yarn - Package Manager
If the Tracing integration is not enabled, the Profiler component will not work. The Profiler tracks component mount, render duration and updates.
Read more >Troubleshooting for React - Sentry Documentation
By default, Sentry does not capture errors when a resource (like an image or a css file) fails to load. If you would...
Read more >react-refresh-runtime.development.js:315 uncaught typeerror
And now the data does not load and in info.error I get: "Uncaught TypeError: Cannot read properties of undefined (reading 'map')". Open side...
Read more >@sentry/react - npm Package Health Analysis | Snyk
All security vulnerabilities belong to production dependencies of direct and indirect packages. License: MIT. Security Policy: No.
Read more >Error when deploying react app and it keeps sayings ...
I faced the similar issue, I just opened the package.json file once and closed it. Ran npm start again and issue got resolved....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think it can be simplified by just adding this.
Had the same problem. What helps is to set the environment variables
NODE_ENV=production, e.g., withcross-envin your package.json scriptbuild:I also think the
modeshould not alter thePRODenvironment variable in Vite, i.e., sometimes not making a production build.