{"id":"8308df14603d1528","repo":"vitejs/vite","slug":"cannot-use-sourcemapinterceptor-node-because","errorCode":null,"errorMessage":"Cannot use \"sourcemapInterceptor: 'node'\" because global \"process\" variable is not available.","messagePattern":"Cannot use \"sourcemapInterceptor: 'node'\" because global \"process\" variable is not available\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vite/src/module-runner/sourcemap/index.ts","lineNumber":7,"sourceCode":"import type { ModuleRunner } from '../runner'\nimport { interceptStackTrace } from './interceptor'\n\nexport function enableSourceMapSupport(runner: ModuleRunner): () => void {\n  if (runner.options.sourcemapInterceptor === 'node') {\n    if (typeof process === 'undefined') {\n      throw new TypeError(\n        `Cannot use \"sourcemapInterceptor: 'node'\" because global \"process\" variable is not available.`,\n      )\n    }\n    /* eslint-disable n/no-unsupported-features/node-builtins -- process.setSourceMapsEnabled and process.sourceMapsEnabled */\n    if (typeof process.setSourceMapsEnabled !== 'function') {\n      throw new TypeError(\n        `Cannot use \"sourcemapInterceptor: 'node'\" because \"process.setSourceMapsEnabled\" function is not available. Please use Node >= 16.6.0.`,\n      )\n    }\n    const isEnabledAlready = process.sourceMapsEnabled ?? false\n    process.setSourceMapsEnabled(true)\n    return () => !isEnabledAlready && process.setSourceMapsEnabled(false)\n    /* eslint-enable n/no-unsupported-features/node-builtins */\n  }\n  return interceptStackTrace(\n    runner,\n    typeof runner.options.sourcemapInterceptor === 'object'\n      ? runner.options.sourcemapInterceptor","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/module-runner/sourcemap/index.ts#L1-L25","documentation":"Thrown by enableSourceMapSupport when the runner is configured with sourcemapInterceptor: 'node' but the global process variable is undefined. The 'node' interceptor mode uses Node.js's built-in process.setSourceMapsEnabled() to remap stack traces, which requires the process global. In environments where process is not available (browsers, some edge runtimes, sandboxed contexts), this configuration is invalid.","triggerScenarios":"Creating a ModuleRunner with { sourcemapInterceptor: 'node' } in a non-Node environment, or in a Node context where process has been polyfilled away or is not exposed globally (e.g., some bundlers strip process, or a custom runtime overrides globals).","commonSituations":"Running the module runner in an edge worker, browser extension context, or Deno (without --unstable-node-globals) where process is not defined. Using a bundler that replaces process.env but not the process global itself. Sandbox environments (vm2, isolated-vm) that don't expose process.","solutions":["If running in a non-Node environment, omit sourcemapInterceptor or set it to an object with custom retrieveFile/retrieveSourceMap handlers.","If you need source map support in-browser, use the default interceptor (omit the option) which uses Error.prepareStackTrace-based interception.","If running in Node, ensure the process global is available (don't override or delete it).","Set sourcemapInterceptor: false to disable source map interception entirely if you don't need it."],"exampleFix":"// before — requires Node process global\nconst runner = new ModuleRunner({\n  transport,\n  sourcemapInterceptor: 'node'\n})\n// after — use default interceptor (works in any environment)\nconst runner = new ModuleRunner({\n  transport\n  // sourcemapInterceptor omitted -> uses prepareStackTrace-based interception\n})","handlingStrategy":"validation","validationCode":"// Validate environment supports node sourcemap interceptor before using it\nfunction resolveSourcemapInterceptor(option) {\n  if (option === 'node') {\n    if (typeof process === 'undefined') {\n      throw new Error('sourcemapInterceptor: \"node\" requires global process. Use default or false.')\n    }\n    if (typeof process.setSourceMapsEnabled !== 'function') {\n      throw new Error('sourcemapInterceptor: \"node\" requires Node >= 16.6.0')\n    }\n  }\n  return option\n}\n\nconst runner = new ModuleRunner({\n  transport,\n  sourcemapInterceptor: resolveSourcemapInterceptor('node')\n})","typeGuard":"function supportsNodeSourcemapInterceptor(): boolean {\n  return typeof process !== 'undefined' &&\n         typeof process.setSourceMapsEnabled === 'function'\n}","tryCatchPattern":"try {\n  const runner = new ModuleRunner({\n    transport,\n    sourcemapInterceptor: 'node'\n  })\n} catch (e) {\n  if (e.message.includes('sourcemapInterceptor')) {\n    console.warn('Node sourcemap interceptor unavailable, falling back to default')\n    runner = new ModuleRunner({ transport }) // default interceptor\n  }\n}","preventionTips":["Only use sourcemapInterceptor: 'node' when running in a confirmed Node.js environment (>= 16.6.0).","Omit the option or use the default interceptor for browser/edge/Deno runtimes.","Add an environment check helper that all runner instances use to validate interceptor config.","Set sourcemapInterceptor: false when source maps aren't needed to avoid overhead."],"tags":["module-runner","sourcemap","node-environment","process-global"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}