Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR module load errors are not handled #2252

Closed
Rich-Harris opened this issue Feb 25, 2021 · 0 comments · Fixed by #2253
Closed

SSR module load errors are not handled #2252

Rich-Harris opened this issue Feb 25, 2021 · 0 comments · Fixed by #2253

Comments

@Rich-Harris
Copy link
Contributor

Describe the bug

The following code...

try {
  const mod = await server.ssrLoadModule('/non-existent');
  do_something_with(mod);
} catch (e) {
  // error is handled, no warning should appear
}

...results in this:

UnhandledPromiseRejectionWarning: Error: failed to load module for ssr: /non-existent

Reproduction

package.json

{
  "scripts": {
    "start": "node server.js"
  },
  "devDependencies": {
    "vite": "^2.0.1"
  },
  "type": "module"
}

server.js

import vite from 'vite';

async function main() {
  const server = await vite.createServer();

  try {
    await server.ssrLoadModule('/non-existent');
  } catch (e) {
    console.error('handled', e);
  }
}

main();

Expected result: it prints 'handled' along with the error. Actual result: it prints 'handled' alongside the unhandled promise rejection warning.

The culprit is this line...

modulePromise.then(() => pendingModules.delete(url))

...which needs a catch:

-modulePromise.then(() => pendingModules.delete(url))
+modulePromise.catch(() => {}).then(() => pendingModules.delete(url))

System Info

  • vite version: 2.0.3
  • Operating System: MacOS
  • Node version: 12.21.0
  • Package manager (npm/yarn/pnpm) and version: npm 7.5.6
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant