From 7ce307a68cf6e7ad04d875f5648814455825b4b1 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 24 Oct 2024 12:21:06 +0900 Subject: [PATCH] fix(vite-node): fix error stack on Windows --- packages/vite-node/src/server.ts | 1 + test/vite-node/src/watch/source-map.ts | 16 ++++++++++++++++ test/vite-node/test/cli.test.ts | 6 ++++++ 3 files changed, 23 insertions(+) create mode 100644 test/vite-node/src/watch/source-map.ts 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') +})