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

  1. Set `sourcemapInterceptor: false` (or to a custom object interceptor) when running outside Node.
  2. Provide a `process` global polyfill if you genuinely need the Node interceptor in a non-Node runtime.
  3. 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 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


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.sourcemapInterceptor

View on GitHub (pinned to b4d66fee14)