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

fix: throw ssr import error directly (fix #12322) #12324

Merged
merged 5 commits into from
Mar 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 22 additions & 9 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'
import { pathToFileURL } from 'node:url'
import colors from 'picocolors'
import type { ViteDevServer } from '../server'
import {
dynamicImport,
Expand Down Expand Up @@ -203,17 +204,24 @@ async function instantiateModule(
)
} catch (e) {
mod.ssrError = e

if (e.stack && fixStacktrace) {
ssrFixStacktrace(e, moduleGraph)
server.config.logger.error(
`Error when evaluating SSR module ${url}:\n${e.stack}`,
{
timestamp: true,
clear: server.config.clearScreen,
error: e,
},
)
}

server.config.logger.error(
colors.red(
`Error when evaluating SSR module ${url}:` +
(e.importee ? ` failed to import "${e.importee}"\n` : '\n'),
),
{
timestamp: true,
clear: server.config.clearScreen,
error: e,
},
)

delete e.importee
throw e
}

Expand Down Expand Up @@ -257,7 +265,12 @@ async function nodeImport(
try {
const mod = await dynamicImport(url)
return proxyESM(mod)
} catch {}
} catch (err) {
// tell external error handler which mod was imported with error
err.importee = id

throw err
}
bluwy marked this conversation as resolved.
Show resolved Hide resolved
}

// rollup-style default import interop for cjs
Expand Down