Vite 6 change in behavior with noExternal & imports that share name with node builtins #18810
Closed
7 tasks done
Labels
feat: ssr
p3-minor-bug
An edge case that only affects very specific usage (priority)
regression
The issue only appears after a new release
Describe the bug
When using
build.ssr: true
andssr.noExternal: true
, and importing from a package with the same name as a node built-in, vite 6 appears to treat the package as external, but resolves the import path as if it was a package import.This was happening in some nested dependencies of mine.
readable_stream
doesrequire('string_decoder/')
(presumably to force the import to use the package dependency over the node built-in).From what I can guess, it seems like there is a mismatch between two bits of code in the resolution logic. One part sees the package name "string_decoder" and sees that it matches a node built-in and so it gets flagged as external, however, when the import is resolved, it sees the / at the end and resolves to the main export in the output.
Input:
Produces:
which is not a valid import from the node built-in, but also isn't bundled so this fails to execute at runtime if
string_decoder
is not present innode_modules
.In Vite 5, the
string_decoder
package dependency is bundled and included in the output of./dist/index.js
as expected.Reproduction
https://stackblitz.com/edit/vitejs-vite-s9cz6r?file=src%2Findex.js&view=editor
Steps to reproduce
First,
npm install
followed bynpm run build
Running
npm run test
will deletestring_decoder
fromnode_modules
and then execute the output. The expectation is thatstring_decoder
should have been bundled into thedist/index.js
output, but that is not the case so runningdist/index.js
fails.System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.20.3 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm pnpm: 8.15.6 - /usr/local/bin/pnpm npmPackages: vite: ^6.0.1 => 6.0.1
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: