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.

dev/build silently externalizes some dependencies, leading to runtime errors

See original GitHub issue

Describe 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.

https://github.com/vitejs/vite/blob/88ded7f16382d83603511de043785e01ee1e4a3a/packages/vite/src/node/plugins/resolve.ts#L239-L241

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Niputicommented, Feb 28, 2022

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 .mjsas extension

1reaction
JinJianQicommented, Feb 28, 2022

@NfNitLoop I created a PR for this. 😃, See if it can solve your problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic 5 Angular 11 Cordova build prod - random runtime errors
These errors do not result in crashes, the app runs fine afterwards, but some functions are broken. This happens only for some services...
Read more >
Runtime Errors - GeeksforGeeks
Runtime Errors : A runtime error in a program is an error that occurs while the program is running after being successfully compiled....
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