-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Labels
feat: ssrp3-downstream-blockerBlocking the downstream ecosystem to work properly (priority)Blocking the downstream ecosystem to work properly (priority)
Description
Describe the bug
Seeing module runner crashing in Vitest feature when creating error stacktraces inside node:vm where columnOffset causes negative columns.
Stack traces with negative column? Here's 0 deps example in Node:
Details
import { createHook } from "async_hooks";
import { runInThisContext } from "vm";
const resources = new Map();
const hook = createHook({
init(asyncId, type, _triggerAsyncId) {
if (type !== "PROMISE") return;
const stack = new Error("VITEST_DETECT_ASYNC_LEAKS").stack || "";
resources.set(asyncId, { type, stack });
},
destroy(asyncId) {
resources.delete(asyncId);
},
promiseResolve(asyncId) {
resources.delete(asyncId);
},
});
hook.enable();
const codeDefinition = `'use strict';async ()=>{{`;
const code = `\nawait new Promise((resolve) => { console.log('running') });`;
const wrappedCode = `${codeDefinition}${code}\n}}`;
const initModule = runInThisContext(wrappedCode, {
lineOffset: 0,
columnOffset: -codeDefinition.length,
filename: "virtual.mjs",
});
initModule();
hook.disable();
for (const resource of resources.values()) {
console.log(resource.type, resource.stack, "\n");
}Error: VITEST_DETECT_ASYNC_LEAKS
at AsyncHook.init (file:///Users/ari/Git/scripts/async-hooks.mjs:10:19)
at emitInitNative (node:internal/async_hooks:206:43)
at emitInitScript (node:internal/async_hooks:513:3)
at promiseInitHook (node:internal/async_hooks:332:3)
at promiseInitHookWithDestroyTracking (node:internal/async_hooks:336:3)
at virtual.mjs:1:-11
at file:///Users/ari/Git/scripts/async-hooks.mjs:34:1
at ModuleJob.run (node:internal/modules/esm/module_job:343:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
Reproduction
https://stackblitz.com/edit/vitejs-vite-gqrvb5ta
Steps to reproduce
This cannot be reproduced on stackblitz.com due to WebContainer's Node handling stacktraces differently. Download the code and run it locally.
$ node index.mjsSystem Info
System:
OS: macOS 26.2
CPU: (8) arm64 Apple M2
Memory: 723.86 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 22.22.0 - /Users/ari/.nvm/versions/node/v22.22.0/bin/node
npm: 10.9.4 - /Users/ari/.nvm/versions/node/v22.22.0/bin/npm
pnpm: 10.28.2 - /Users/ari/.nvm/versions/node/v22.22.0/bin/pnpm
Browsers:
Safari: 26.2
npmPackages:
vite: 7.1.5 => 7.1.5Used Package Manager
pnpm
Logs
Error: `column` must be greater than or equal to 0 (columns start at column 0)
at originalPositionFor (file:///Users/ari/Git/repros/vite-server/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/module-runner.js:193:24)
at getOriginalPosition (file:///Users/ari/Git/repros/vite-server/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/module-runner.js:237:15)
at mapSourcePosition (file:///Users/ari/Git/repros/vite-server/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/module-runner.js:806:26)
at wrapCallSite (file:///Users/ari/Git/repros/vite-server/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/module-runner.js:863:18)
at Function.prepareStackTrace (file:///Users/ari/Git/repros/vite-server/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/module-runner.js:894:78)
at prepareStackTraceCallback (node:internal/errors:144:29)
at AsyncHook.init (file:///Users/ari/Git/repros/vite-server/index.mjs:45:58)
at emitInitNative (node:internal/async_hooks:206:43)
at emitInitScript (node:internal/async_hooks:513:3)
at promiseInitHook (node:internal/async_hooks:332:3)
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: ssrp3-downstream-blockerBlocking the downstream ecosystem to work properly (priority)Blocking the downstream ecosystem to work properly (priority)