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

Setting build mode to "development" breaks React JSX transform #5885

Closed
7 tasks done
morhekil opened this issue Nov 29, 2021 · 6 comments · Fixed by #8546
Closed
7 tasks done

Setting build mode to "development" breaks React JSX transform #5885

morhekil opened this issue Nov 29, 2021 · 6 comments · Fixed by #8546

Comments

@morhekil
Copy link

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 vercel/next.js#19001, but setting NODE_ENV environment variable to development did not resolve the issue here.

This problem has also been brought up in discussion #5803, and it makes it impossible to debug or find the culprit of broken production builds described in #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

@TJBlackman
Copy link

I also get this error any time I run the build command in ANY mode other than production. To check, I just run the build step, then view the outDir/assets/index.[hash].js and run a ctrl+f for jsxDEV. In production mode, 0 references, but with any other mode defined, there's dozens and dozens of references to jsxDEV.

Vite versions from package.json:

  • "@vitejs/plugin-react": "^1.1.1"
  • "vite": "^2.7.1"

@sledorze
Copy link

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

@jochumdev
Copy link

jochumdev commented Jan 24, 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

@floydding
Copy link

run into the same issue here. the above workaround does work tho.

@schmidtc63
Copy link

@pcdummy 's fix worked for me.
Thank you

@bluwy
Copy link
Member

bluwy commented Jun 11, 2022

This seems to be fix in the latest plugin-react version, indirectly through #8280, though it introduces a regression at #8468, so I won't close this just yet. Both issues are conflicting and I'm trying to figure out a balance point.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants