diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index 0bab9703c075c7..c7bf13ca0929ab 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -295,7 +295,7 @@ async function loadAndTransform( // to resolve and display them in a meaningful way (rather than // with absolute paths). if (path.isAbsolute(sourcePath)) { - map.sourceRoot = path.dirname(mod.file) + path.sep + map.sourceRoot = path.dirname(mod.file) map.sources[sourcesIndex] = path.relative( path.dirname(mod.file), sourcePath, diff --git a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts index 5be3c0a23b3e24..98dad19c1b9683 100644 --- a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts +++ b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts @@ -69,7 +69,7 @@ describe.runIf(isServe)('serve', () => { expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` { "mappings": "AAAA;EACE,UAAU;AACZ;;ACAA;EACE,UAAU;AACZ", - "sourceRoot": "/root/", + "sourceRoot": "/root", "sources": [ "be-imported.css", "linked-with-import.css", diff --git a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts index b86af9df81aeca..2908faca709fcd 100644 --- a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts +++ b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts @@ -24,7 +24,7 @@ if (!isBuild) { expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` { "mappings": "AAAO,aAAM,MAAM;", - "sourceRoot": "/root/", + "sourceRoot": "/root", "sources": [ "bar.ts", ], diff --git a/playground/ssr-html/__tests__/ssr-html.spec.ts b/playground/ssr-html/__tests__/ssr-html.spec.ts index 2bb082aa7407c2..e4360f698292bf 100644 --- a/playground/ssr-html/__tests__/ssr-html.spec.ts +++ b/playground/ssr-html/__tests__/ssr-html.spec.ts @@ -3,6 +3,7 @@ import { promisify } from 'node:util' import path from 'node:path' import fetch from 'node-fetch' import { describe, expect, test } from 'vitest' +import { normalizePath } from 'vite' import { port } from './serve' import { editFile, isServe, page, untilUpdated } from '~utils' @@ -83,10 +84,14 @@ describe.runIf(isServe)('stacktrace', () => { const reg = new RegExp( // TODO: ts without sourcemaps will resolve column to 8 which should be 9 - path.resolve(__dirname, '../src') + '/error\\.' + ext + ':2:[89]', + normalizePath( + path.resolve(__dirname, '../src', `error.${ext}`), + ).replace('.', '\\.') + ':2:[89]', + 'i', ) lines.forEach((line) => { + console.log(line.trim()) expect(line.trim()).toMatch(reg) }) }) diff --git a/playground/test-utils.ts b/playground/test-utils.ts index 9bfbb2d550851b..048f6c8dd9b0e7 100644 --- a/playground/test-utils.ts +++ b/playground/test-utils.ts @@ -308,7 +308,7 @@ export const formatSourcemapForSnapshot = (map: any): any => { delete m.names m.sources = m.sources.map((source) => source.replace(root, '/root')) if (m.sourceRoot) { - m.sourceRoot = m.sourceRoot.replace(root + path.sep, '/root/') + m.sourceRoot = m.sourceRoot.replace(root, '/root') } return m }