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
- Use @babel/standalone for browser compilation.
- Set `inputSourceMap: false` in the transform options to skip the external map lookup.
- 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
- Strip external sourceMappingURL comments before browser transforms.
- Default to inputSourceMap: false in browser builds.
- Prefer @babel/standalone for browser compilation.
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
- Transforming files is not supported in browsers
- Cannot load ${name} relative to ${dirname} in a browser
- Cannot load plugin ${name} relative to ${dirname} in a brows
- Cannot load preset ${name} relative to ${dirname} in a brows
- ${msg(loc)} must be a boolean, object, or undefined
AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03).
Data as JSON: /data/errors/fc9d5f29f19ea87d.json.
Report an issue: GitHub.