{"record":{"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/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/module-runner/sourcemap/index.ts#L1-L25","documentation":"`enableSourceMapSupport` honors `sourcemapInterceptor: 'node'`, which delegates to Node's built-in `process.setSourceMapsEnabled`. If the global `process` object is entirely absent (e.g. running the module runner in a browser/edge worker/non-Node runtime), the option cannot work and the runner throws a TypeError.","triggerScenarios":"Constructing a ModuleRunner with `sourcemapInterceptor: 'node'` (or defaulting to it) in a runtime where `globalThis.process` is undefined - browsers, Deno, Cloudflare Workers, or a sandbox that strips Node globals.","commonSituations":"Reusing a Node-targeted runner config in a browser/edge environment. Test sandboxes that stub out `process`. Bundling the runner for the browser without polyfilling `process`.","solutions":["Set `sourcemapInterceptor: false` (or to a custom object interceptor) when running outside Node.","Provide a `process` global polyfill if you genuinely need the Node interceptor in a non-Node runtime.","Use `sourcemapInterceptor: 'object'`-style custom interceptor instead of `'node'`."],"exampleFix":"// before\nnew ModuleRunner({ transport, sourcemapInterceptor: 'node' }) // in browser\n// after\nnew ModuleRunner({ transport, sourcemapInterceptor: false })","handlingStrategy":"validation","validationCode":"function resolveSourcemapInterceptorForRuntime(opt: 'node' | false | object | undefined) {\n  if (opt === 'node' && typeof process === 'undefined') {\n    return false // or a custom object interceptor\n  }\n  return opt\n}","typeGuard":"function nodeProcessAvailable(): boolean {\n  return typeof process !== 'undefined'\n}","tryCatchPattern":null,"preventionTips":["When running the module runner in non-Node runtimes, set sourcemapInterceptor: false.","Feature-detect `typeof process !== 'undefined'` before choosing the 'node' interceptor."],"tags":["module-runner","sourcemap","node-runtime","environment"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}