Describe the bug
If a module throws an error during evaluation, then ssrLoadModule will fail with that error. But if you call ssrLoadModule a second time, it 'succeeds', returning a module stub:
// first attempt
try {
const mod = await server.ssrLoadModule('./bad.js');
} catch (e) {
// we end up here, as expected
}
// subsequent attempts
try {
const mod = await server.ssrLoadModule('./bad.js');
// we end up here, with an empty module
} catch (e) {
// ...
}
Browsers and Node don't work this way — if a module blows up during evaluation, importing it a second time will fail. Importantly, it doesn't re-evaluate the module — it's more akin to this:
const promise = Promise.reject(new Error('bad'));
try {
await promise;
} catch (e) {
console.log(e.message); // 'bad';
}
try {
await promise;
} catch (e) {
console.log(e.message); // 'bad';
}
Reproduction
https://github.com/Rich-Harris/vite-double-import-repro
System Info
System:
OS: macOS 12.0.1
CPU: (10) arm64 Apple M1 Max
Memory: 72.00 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn
npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
Browsers:
Chrome: 98.0.4758.102
Firefox: 97.0
Safari: 15.1
npmPackages:
vite: ^2.8.4 => 2.8.4
Used Package Manager
npm
Logs
No response
Validations
Describe the bug
If a module throws an error during evaluation, then
ssrLoadModulewill fail with that error. But if you callssrLoadModulea second time, it 'succeeds', returning a module stub:Browsers and Node don't work this way — if a module blows up during evaluation, importing it a second time will fail. Importantly, it doesn't re-evaluate the module — it's more akin to this:
Reproduction
https://github.com/Rich-Harris/vite-double-import-repro
System Info
System: OS: macOS 12.0.1 CPU: (10) arm64 Apple M1 Max Memory: 72.00 MB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm Browsers: Chrome: 98.0.4758.102 Firefox: 97.0 Safari: 15.1 npmPackages: vite: ^2.8.4 => 2.8.4Used Package Manager
npm
Logs
No response
Validations