question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`plugin-react`: Fails to bundle `@sentry/react` if `mode` is not `production`

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:8
  • Comments:6

github_iconTop GitHub Comments

1reaction
rohmanhmcommented, Aug 9, 2022

Had the same problem. Solved by adding NODE_ENV=production to .env.staging file.

// package.json
{
  // ...
   "scripts": {
     // ...
     "build:staging": "NODE_ENV=production tsc && vite build --mode staging",
     // ...
   },
   // ...
}
# .env.staging
NODE_ENV=production
VITE_APP_TITLE=My App (staging)

I think it can be simplified by just adding this.

"build:staging": "tsc && NODE_ENV=production vite build --mode staging",
1reaction
pantajoecommented, Jul 26, 2022

Had the same problem. What helps is to set the environment variables NODE_ENV=production, e.g., with cross-env in your package.json script build:

// package.json
{
  // ...
   "scripts": {
     // ...
     "build": "cross-env NODE_ENV=production tsc && vite build",
     // ...
   },
   // ...
}

I also think the mode should not alter the PROD environment variable in Vite, i.e., sometimes not making a production build.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found