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

ssrLoadModule promises resolve even if evaluation fails #2078

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

ssrLoadModule promises resolve even if evaluation fails #2078

Rich-Harris opened this issue Feb 18, 2021 · 0 comments · Fixed by #2079

Comments

@Rich-Harris
Copy link
Contributor

Describe the bug

Suppose you have a module, bad-module.js, which throws an error on evaluation. If you import('bad-module.js') the promise will reject, but if you load it with ssrLoadModule('bad-module.js'), the promise resolves to a module record with no exports.

This means it's difficult to know if an error occurred (especially if you don't know what shape the module should have) and impossible (AFAICT) to get hold of the error itself. For consistency, I'd expect it the error here to be rethrown:

} catch (e) {
e.stack = ssrRewriteStacktrace(e.stack, moduleGraph)
server.config.logger.error(
`Error when evaluating SSR module ${url}:\n${e.stack}`,
{
timestamp: true,
clear: true
}
)
}

(As an aside, clear: true means that the clearScreen option isn't respected — not sure if this function has access to that config?)

Reproduction

https://github.com/Rich-Harris/vite-ssr-load-errors

System Info

  • vite version: 2.0.1
  • Operating System: Mac OS
  • Node version: 12.18.3
  • Package manager (npm/yarn/pnpm) and version: npm 6.14.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