dev/build silently externalizes some dependencies, leading to runtime errors
See original GitHub issueDescribe the bug
Vite has some resolver plugins that cause it to “externalize” some dependencies by name. Instead of giving an error at bundle/build time, the dependency is just dropped from the dependency graph.
This leaves you to get runtime errors when things run in the browser.
If Vite had errors (or even warnings) about this, the user could look for other libraries or polyfills to resolve the issue.
Reproduction
https://github.com/NfNitLoop/vite-issue/commit/5150380bfb17a067ed1623b3b4003a71d288aea7
System Info
n/a.
Used Package Manager
npm
Logs
When running npm run build && npm run preview
:
Uncaught TypeError: Cannot read properties of undefined (reading ‘from’) at vendor.93cea733.js:1:1014 at vendor.93cea733.js:1:1703
When running npm run dev
:
[vite] connecting… index.js:12 Uncaught TypeError: Cannot read properties of undefined (reading ‘from’) at node_modules/safe-buffer/index.js (index.js:12:12) at __require (bs58check.js?v=f7e2e0ea:10:50) at node_modules/hash-base/index.js (index.js:2:14) at __require (bs58check.js?v=f7e2e0ea:10:50) at node_modules/md5.js/index.js (index.js:3:16) at __require (bs58check.js?v=f7e2e0ea:10:50) at node_modules/create-hash/browser.js (browser.js:3:11) at __require (bs58check.js?v=f7e2e0ea:10:50) at node_modules/bs58check/index.js (index.js:3:18) at __require (bs58check.js?v=f7e2e0ea:10:50) client.ts:58 [vite] connected.
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/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 2 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
polyfills in vite core will never be a builtin functionality. better error messages are fine, would especially be good in build mode. dependencies should be fixed to not include node builtins as they don’t exist in the browser and preferably export correct esm version with
.mjs
as extension@NfNitLoop I created a PR for this. 😃, See if it can solve your problem.