babel/babel · error · Error

Reading input source map files is not supported in browsers

Error message

Reading input source map files is not supported in browsers

What it means

The browser build of @babel/core replaces the external-source-map file reader with a stub (read-input-source-map-file-browser.ts) that always throws, because reading a .map file from disk is impossible without a filesystem.

Source

Thrown at packages/babel-core/src/transformation/read-input-source-map-file-browser.ts:2

export default function readInputSourceMapFile(): never {
  throw new Error(
    "Reading input source map files is not supported in browsers",
  );
}

View on GitHub (pinned to 06b6eae39d)

Solutions

  1. Use @babel/standalone for browser compilation.
  2. Set `inputSourceMap: false` in the transform options to skip the external map lookup.
  3. Strip external sourceMappingURL comments from the input before transforming.

Example fix

// before
transform(code, { sourceMaps: true }); // code has //# sourceMappingURL=app.js.map

// after
transform(code, { sourceMaps: true, inputSourceMap: false });
Defensive patterns

Strategy: validation

Validate before calling

function isBrowser() {
  return typeof window !== 'undefined';
}
const opts = isBrowser()
  ? { sourceMaps: true, inputSourceMap: false }
  : { sourceMaps: true };

Type guard

const supportsFileSystem = () =>
  typeof process !== 'undefined' && typeof process.versions?.node === 'string';

Try / catch

try {
  transform(code, { sourceMaps: true });
} catch (err) {
  if (/Reading input source map files is not supported in browsers/.test(err.message)) {
    transform(code, { sourceMaps: true, inputSourceMap: false });
  } else throw err;
}

Prevention

When it happens

Trigger: Transforming code in a browser build where the source contains a non-inline `//# sourceMappingURL=foo.map` comment AND inputSourceMap is not disabled.

Common situations: Shipping @babel/core (not @babel/standalone) to the browser; transforming pre-compiled code that still references external maps.

Related errors


AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03). Data as JSON: /data/errors/fc9d5f29f19ea87d.json. Report an issue: GitHub.