vitejs/vite · error · TypeError
Cannot use "sourcemapInterceptor: 'node'" because global…
Error message
Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.
What it means
`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.
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'`.
Example fix
// before
new ModuleRunner({ transport, sourcemapInterceptor: 'node' }) // in browser
// after
new ModuleRunner({ transport, sourcemapInterceptor: false }) Defensive patterns
Strategy: validation
Validate before calling
function resolveSourcemapInterceptorForRuntime(opt: 'node' | false | object | undefined) {
if (opt === 'node' && typeof process === 'undefined') {
return false // or a custom object interceptor
}
return opt
} Type guard
function nodeProcessAvailable(): boolean {
return typeof process !== 'undefined'
} Prevention
- When running the module runner in non-Node runtimes, set sourcemapInterceptor: false.
- Feature-detect `typeof process !== 'undefined'` before choosing the 'node' interceptor.
When it happens
Trigger: 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.
Common situations: 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`.
Related errors
- Cannot use "sourcemapInterceptor: 'node'" because…
- Cannot send non-custom events from the client to the server.
- Cannot send non-custom events from the server to the client.
- HMR is not supported by this runner transport, but `hmr`…
- invoke was called before connect
AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11).
Data as JSON: /api/errors/8308df14603d1528.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vite/src/module-runner/sourcemap/index.ts:7
import type { ModuleRunner } from '../runner'
import { interceptStackTrace } from './interceptor'
export function enableSourceMapSupport(runner: ModuleRunner): () => void {
if (runner.options.sourcemapInterceptor === 'node') {
if (typeof process === 'undefined') {
throw new TypeError(
`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`,
)
}
/* eslint-disable n/no-unsupported-features/node-builtins -- process.setSourceMapsEnabled and process.sourceMapsEnabled */
if (typeof process.setSourceMapsEnabled !== 'function') {
throw new TypeError(
`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`,
)
}
const isEnabledAlready = process.sourceMapsEnabled ?? false
process.setSourceMapsEnabled(true)
return () => !isEnabledAlready && process.setSourceMapsEnabled(false)
/* eslint-enable n/no-unsupported-features/node-builtins */
}
return interceptStackTrace(
runner,
typeof runner.options.sourcemapInterceptor === 'object'
? runner.options.sourcemapInterceptorView on GitHub (pinned to b4d66fee14)