-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
vitejs/vite
#7164Labels
Description
Describe the bug
An await import statement with a catch block runs well in NodeJS but fails in vitest
node --eval "require('./index').run().then(console.log)"
false # console output
Reproduction
// index.js
exports.run = async () => {
try {
await import('./404.js');
}
catch (ex) {
if (ex.code === 'MODULE_NOT_FOUND' || ex.code === 'ERR_MODULE_NOT_FOUND') {
return false;
}
throw ex;
}
};// index.test.js
import {test, expect} from 'vitest';
import {run} from './index';
test('run', async () => {
const value = await run();
expect(value).toBe(false);
});Running vitest produces errors:
RUN /Users/otakustay/Downloads/vi
❯ index.test.js (0)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL index.test.js [ index.test.js ]
Error: Failed to resolve import "./404.js" from "index.js". Does the file exist?
❯ formatError node_modules/vite/dist/node/chunks/dep-4a9cff06.js:42631:46
❯ TransformContext.error node_modules/vite/dist/node/chunks/dep-4a9cff06.js:42627:19
❯ normalizeUrl node_modules/vite/dist/node/chunks/dep-4a9cff06.js:81376:26
❯ async TransformContext.transform node_modules/vite/dist/node/chunks/dep-4a9cff06.js:81516:57
❯ async Object.transform node_modules/vite/dist/node/chunks/dep-4a9cff06.js:42847:30
❯ async doTransform node_modules/vite/dist/node/chunks/dep-4a9cff06.js:57929:29
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests no tests
Time 355ms (in thread 0ms, Infinity%)
System Info
System:
OS: macOS 12.1
CPU: (10) arm64 Apple M1 Max
Memory: 8.58 GB / 64.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.0 - /var/folders/hm/3h2qtx2x2jddg130mktcrztm0000gn/T/fnm_multishells/79464_1640586000170/bin/node
Yarn: 1.22.15 - /var/folders/hm/3h2qtx2x2jddg130mktcrztm0000gn/T/fnm_multishells/79464_1640586000170/bin/yarn
npm: 8.3.0 - /var/folders/hm/3h2qtx2x2jddg130mktcrztm0000gn/T/fnm_multishells/79464_1640586000170/bin/npm
Browsers:
Chrome: 96.0.4664.110
Safari: 15.2
npmPackages:
vite: ^2.7.7 => 2.7.7
vitest: ^0.0.115 => 0.0.115Used 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.
Reactions are currently unavailable