diff --git a/packages/vite-node/src/server.ts b/packages/vite-node/src/server.ts index 4ad21e03e56a..5a2baa06cf11 100644 --- a/packages/vite-node/src/server.ts +++ b/packages/vite-node/src/server.ts @@ -190,6 +190,7 @@ export class ViteNodeServer { } getSourceMap(source: string) { + source = normalizeModuleId(source) const fetchResult = this.fetchCache.get(source)?.result if (fetchResult?.map) { return fetchResult.map diff --git a/test/vite-node/src/watch/source-map.ts b/test/vite-node/src/watch/source-map.ts new file mode 100644 index 000000000000..81677fe72f24 --- /dev/null +++ b/test/vite-node/src/watch/source-map.ts @@ -0,0 +1,16 @@ +// 1 +// 1 +async function main() { + try { + // 2 + // 2 + throw new Error('boom') + } + catch (e) { + // eslint-disable-next-line no-console + console.log(e) + } +} +// 3 +// 3 +main() diff --git a/test/vite-node/test/cli.test.ts b/test/vite-node/test/cli.test.ts index fea9d13800bb..5e81e4c88751 100644 --- a/test/vite-node/test/cli.test.ts +++ b/test/vite-node/test/cli.test.ts @@ -52,3 +52,9 @@ it.each(['index.js', 'index.cjs', 'index.mjs'])('correctly runs --watch %s', asy editFile(entryPath, c => c.replace('test 1', 'test 2')) await viteNode.waitForStdout('test 2') }) + +it('error stack', async () => { + const entryPath = resolve(__dirname, '../src/watch/source-map.ts') + const { viteNode } = await runViteNodeCli('--watch', entryPath) + await viteNode.waitForStdout('source-map.ts:7:11') +})