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.

Setting build mode to "development" breaks React JSX transform

See original GitHub issue

Describe the bug

If "mode": "development" is specified in vite.config.js, and the project uses React JSX - then this results in a broken build, which displays in the console the following error when it first encounters a JSX tag:

jsxDevRuntime.exports.jsxDEV is not a function

jsxDevRuntime.exports at that point do indeed have jsxDEV value set to undefined. Looks like some part of the transform is not being set to development mode in this case, and doesn’t produce jsxDEV data.

This seems similar to https://github.com/vercel/next.js/issues/19001, but setting NODE_ENV environment variable to development did not resolve the issue here.

This problem has also been brought up in discussion https://github.com/vitejs/vite/discussions/5803, and it makes it impossible to debug or find the culprit of broken production builds described in https://github.com/vitejs/vite/issues/2139.

Is there any workaround to get development-mode build working, however hacky it might be?

Reproduction

https://github.com/morhekil/vite-bug-example

This is just a trimmed down standard initial Vite repo

System Info

System:
    OS: macOS 11.6
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 163.62 MB / 32.00 GB
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 12.22.1 - /usr/local/opt/node@12/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.12 - /usr/local/opt/node@12/bin/npm
  Browsers:
    Chrome: 96.0.4664.55
    Firefox: 94.0.2
    Safari: 15.0
  npmPackages:
    @vitejs/plugin-react: ^1.0.0 => 1.1.0
    vite: ^2.6.4 => 2.6.14

Used Package Manager

yarn

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
jochumdevcommented, Mar 1, 2022

Found a workaround for that:

  plugins: [
    process.env.MODE !== 'production' ? react({
      jsxRuntime: 'classic',
    }) : react(),
    svgLoader(),
  ],
NODE_ENV=development MODE=development yarn run vite build
4reactions
sledorzecommented, Dec 16, 2021

Same here, this is stacking atop other problems preventing production deployments…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the New JSX Transform
Together with the React 17 release, we've wanted to make a few improvements to the JSX transform, but we didn't want to break...
Read more >
How Does the Development Mode Work?
Bundling and running different code in development and production is powerful. In development mode, React includes many warnings that help ...
Read more >
The best webpack configurations for React applications
If you've struggled to configure webpack for your React app, look no further. We cover both generic and specific config needs.
Read more >
Upgrade React-App to use JSX transform
Upgrade React-App to use JSX transform - breaks the app (Propery 'React' doesn't exist) · Ask Question. Asked 9 months ago. Modified 9...
Read more >
Complete Guide to Webpack Configuration for React
We will also be creating a src folder inside our project root directory that will hold our JavaScript and JSX files for our...
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