-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Copy link
Labels
feat: sourcemapSourcemap supportSourcemap supportfeat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
For esm external:
fixtures/esm-external/index.js
var _padding_______________________; export function outer(fn) { return inner(fn); } function inner(fn) { return fn(); }and the user code (entry):
- repro-vite-entry.js
import { outer } from "test-esm-external";
function userFn() {
throw new Error("boom");
}
outer(userFn);running it on module runner with prepareStackTrace shows wrong stack trace column for esm external:
- repro-vite.js
import { createServerModuleRunner } from "vite";
import { createServer } from "vite";
async function main() {
const server = await createServer({
configFile: false,
});
await server.listen();
const runner = createServerModuleRunner(server.environments.ssr, {
hmr: false,
sourcemapInterceptor: "prepareStackTrace",
});
await runner.import("./repro-vite-entry.js");
await server.close();
}
main();$ node repro-vite.js
/yyy/repro-vite-entry.js:7
throw new Error("boom");
^
Error: boom
at userFn (/yyy/repro-vite-entry.js:4:9)
at inner (file:///xxx/node_modules/test-esm-external/index.js:1:52) ⚠️ expected 114 = 52 + 62
at outer (file:///xxx/node_modules/test-esm-external/index.js:1:11) ⚠️ expected 73 = 11 + 62
at /yyy/repro-vite-entry.js:7:6
at ESModulesEvaluator.runInlinedModule (file:///yyy/node_modules/vite/dist/node/module-runner.js:913:3)
at ModuleRunner.directRequest (file:///yyy/node_modules/vite/dist/node/module-runner.js:1146:59)
at ModuleRunner.cachedRequest (file:///yyy/node_modules/vite/dist/node/module-runner.js:1053:73)
at ModuleRunner.import (file:///yyy/node_modules/vite/dist/node/module-runner.js:1014:10)
at main (file:///yyy/repro-vite.js:13:3)
Node.js v24.13.0The expected behavior is to match stack columns to be same as native node execution
$ node repro-vite-entry.js
file:///yyy/repro-vite-entry.js:4
throw new Error("boom");
^
Error: boom
at userFn (file:///yyy/repro-vite-entry.js:4:9)
at inner (file:///xxx/node_modules/test-esm-external/index.js:1:114)
at outer (file:///xxx/node_modules/test-esm-external/index.js:1:73)
at file:///yyy/repro-vite-entry.js:7:1
at ModuleJob.run (node:internal/modules/esm/module_job:413:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:660:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)
Node.js v24.13.0See here for full detail https://github.com/hi-ogawa/reproductions/tree/main/vitest-9003-source-map-external#vite-issue It appears "subtraction by 62" is coming from
vite/packages/vite/src/module-runner/sourcemap/interceptor.ts
Lines 369 to 371 in 84079a8
| const headerLength = 62 | |
| if (line === 1 && column > headerLength && !frame.isEval()) | |
| column -= headerLength |
The issue is discovered while investigating vitest-dev/vitest#9152 (running minified preact on vitest happy-dom)
Reproduction
https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vitest-9003-source-map-external
Steps to reproduce
- download https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vitest-9003-source-map-external?file=repro-vite.js
- run
pnpm i, then comparenode repro-vite.jsandnode repro-vite-entry.js
System Info
System:
OS: Linux 6.18 Arch Linux
CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
Memory: 14.18 GB / 31.05 GB
Container: Yes
Shell: 5.3.9 - /usr/bin/bash
Binaries:
Node: 24.13.0 - /run/user/1000/fnm_multishells/82414_1770259029960/bin/node
npm: 11.6.2 - /run/user/1000/fnm_multishells/82414_1770259029960/bin/npm
pnpm: 10.24.0 - /run/user/1000/fnm_multishells/82414_1770259029960/bin/pnpm
bun: 1.3.5 - /home/hiroshi/.local/bin/bun
Deno: 2.6.6 - /home/hiroshi/.local/bin/deno
Browsers:
Chromium: 143.0.7499.192
Firefox: 146.0.1
Firefox Developer Edition: 146.0.1
npmPackages:
vite: ^7.3.1 => 7.3.1Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: sourcemapSourcemap supportSourcemap supportfeat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)