-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Describe the bug
For this code:
try {
await import('no-such-package');
} catch (e) {
console.log('code:', e.code);
console.log('message:', e.message);
}On Node
❯ node src/repro.js
code: ERR_MODULE_NOT_FOUND
message: Cannot find package 'no-such-package' imported from /home/projects/vitest-dev-vitest-53av14/src/repro.js
On Vitest
❯ vitest
stdout | src/repro.test.js > repro
code: undefined
message: Failed to load url no-such-package (resolved id: no-such-package) in /home/projects/vitest-dev-vitest-53av14/src/repro.test.js. Does the file exist?It looks like this was brought up previously in #326. It doesn't throw during import analysis anymore, but dynamic import error still doesn't have ERR_MODULE_NOT_FOUND code (or maybe it did when it's fixed but regression).
There are some places injecting ERR_MODULE_NOT_FOUND, so maybe it works in some cases, but not the basic case above.
vitest/packages/vite-node/src/client.ts
Line 296 in 5e6de27
| value: 'ERR_MODULE_NOT_FOUND', |
Vite SSR injects ERR_MODULE_NOT_FOUND https://github.com/vitejs/vite/blob/95020ab49e12d143262859e095025cf02423c1d9/packages/vite/src/node/ssr/fetchModule.ts#L78, so it's working there as well.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-53av14?file=src%2Frepro.test.js
System Info
(stackblitz)
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:
@vitest/ui: latest => 2.1.2
vite: latest => 5.4.8
vitest: latest => 2.1.2Used Package Manager
npm
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.
- 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status