-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
Vitest seems to suppress errors when importing named exports that do not exist, but the file does (e.g. import { LolNotReal } from './utils.js'; which I do in my reproduction), with the resulting import having a value of undefined. This is problematic since when the actual code is executed with Node, Node will crash.
I'd expect Vitest to also fail in this scenario – otherwise our tests do not give confidence that this code works.
This bug also occurs with TypeScript, but I provided a JS-only minimum reproduction to remove that factor. In my reproduction both files are ESM, to remove CJS quirks out of the equation.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-lomnlkfi?file=src%2Fbasic.js
If you run npm run test you will see the test imports the file and passes, even logging the line showing the value of the import is undefined.
But if you run node src/basic.js you will see:
❯ node src/basic.js
file:///home/projects/vitest-dev-vitest-lomnlkfi/src/basic.js:1
import { LolNotReal } from './utils.js';
^^^^^^^^^^
file:///home/projects/vitest-dev-vitest-lomnlkfi/src/basic.js:1
import { LolNotReal } from './utils.js';
^^^^^^^^^^
SyntaxError: The requested module './utils.js' does not provide an export named 'LolNotReal'
at ModuleJob._instantiate (https://vitestdevvitestlomnlkfi-t2wm.w-credentialless-staticblitz.com/builtins.97a3df4f.js:158:2290)
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: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@vitest/ui: latest => 4.0.17
vite: latest => 7.3.1
vitest: latest => 4.0.17Used 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.