Development mode transpiles correctly while build doesn't.
See original GitHub issueDescribe the bug
I am using the following dependency: https://github.com/bitcoinjs/bip39
This loads bip39 and works perfectly when running yarn dev(I did have to use some work arounds to get it running), when building it breaks.
I’d like to understand why this works under development but not when I build the entire project. It seems to be related to commonjs because bip39 uses require. This is perfectly transpiled when using development but breaks when build.
Reproduction
Miminal reproduction: https://github.com/jimbertools/vite-bip39 This loads bip39 and works perfectly when running yarn dev(I did have to use some work arounds to get it running), when building it breaks.
System Info
╰─❯ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
npx: installed 1 in 0.904s
System:
OS: Linux 5.13 Pop!_OS 20.04 LTS
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 23.09 GB / 30.98 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 14.18.1 - /usr/bin/node
Yarn: 1.22.15 - ~/.yarn/bin/yarn
npm: 6.14.15 - /usr/bin/npm
Browsers:
Chrome: 96.0.4664.45
Firefox: 94.0
Used Package Manager
yarn
Logs
No response
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 https://github.com/vuejs/vue-next 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 2 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Typescript transpile errors appear only on production server
I am cloning my repo during the deploy process so I can't do this unless I include my build in my repo. Switch...
Read more >Troubleshooting - Turborepo
My dependency isn't being built correctly. Are you properly bundling and transpiling the dependency before building the application?
Read more >How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >TypeScript Compiling with Visual Studio Code
TypeScript is a typed superset of JavaScript that transpiles to plain JavaScript. It offers classes, modules, and interfaces to help you build robust ......
Read more >Comparing the New Generation of Build Tools - CSS-Tricks
It doesn't provide many of the developer conveniences you might find ... to start as server and run esbuild's watch mode at the...
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 FreeTop 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
Top GitHub Comments
Rollup commonjs plugin set
ignoreTryCatch
default astrue
at version 21.0.0(use safe default value for ignoreTryCatch), and vite upgrade commonjs plugin to this version at it’s 2.6.3 version(#5173), maybe this is the cause of the problem.Try to set
ignoreTryCatch
to false invite.config
and the problem maybe solved:Some libraries, including the one I use, may use
require
to import other libraries and wrap them in try catch statements, commonjs plugin under version 21.0.0 will translate this code to ESM by default but the new version will not.Similarly, I have encountered the same problem. In my case, the package that is causing this issue is: dagre which is a legacy commonJS package and is no longer maintained.
My app works perfectly in development mode but breaks in production when it is build by rollup with the following error:
This issue only appears in version 2.6.3 and up. It does not appear in version 2.6.2. I believe this is related to this pull request: #5173