Skip to content

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

@NfNitLoop

Description

@NfNitLoop

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.

// node built-ins.
// externalize if building for SSR, otherwise redirect to empty module
if (isBuiltin(id)) {

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

NfNitLoop/vite-issue@5150380

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions