Skip to content
Latchkey

Webpack source-map-loader "Failed to parse source map" - Fix in CI

source-map-loader tries to load each module's referenced source map. When a dependency points at a .map that is missing or malformed, the loader emits a warning per file. On CRA or CI=true builds that treat warnings as errors, those warnings fail the build.

What this error means

The build floods with Failed to parse source map from '<node_modules path>': Error: ENOENT warnings, and in CI (warnings-as-errors) the build then fails. The warnings point inside node_modules, not your code.

webpack output
WARNING in ./node_modules/some-lib/dist/index.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/app/node_modules/some-lib/src/index.ts'
file: Error: ENOENT: no such file or directory

Diagnose it: is it resolution, transform, or memory?

Bundler failures in CI fall into three families and the error text often points at the wrong one. A module that resolves on your machine and not on the runner is nearly always case sensitivity or a missing optional dependency; a transform error is a config or version mismatch; and an unexplained kill with no stack is the out-of-memory reaper, not a build error at all.

Terminal
# 1. resolution: does the file exist with EXACTLY that case?
git ls-files | grep -i "the/imported/path"

# 2. transform: what versions is CI actually resolving?
npm ls webpack vite rollup esbuild typescript 2>/dev/null | head -20

# 3. memory: was it killed rather than failed?
#    exit 137 = SIGKILL (OOM). Nothing in the bundler log will explain it.
node --max-old-space-size=4096 node_modules/.bin/vite build

Common causes

A dependency ships a bad sourceMappingURL

The published package references a source map (//# sourceMappingURL=...) that was not included in the npm tarball, so source-map-loader cannot find it.

CI treats warnings as errors

Create React App and many pipelines set CI=true, which promotes warnings to errors - so otherwise-harmless source-map warnings fail the build.

How to fix it

Exclude node_modules from source-map-loader

Only process your own source for maps, so broken dependency maps are ignored.

webpack.config.js
// webpack.config.js
{
  test: /\.[cm]?js$/,
  enforce: 'pre',
  use: ['source-map-loader'],
  exclude: /node_modules/,
}

Ignore the specific warning (CRA)

When you cannot edit the loader config, silence the known-harmless warning.

.env
# .env  (Create React App)
GENERATE_SOURCEMAP=false
# or filter the warning via ignoreWarnings in a custom config:
# ignoreWarnings: [/Failed to parse source map/]

Make the build reproducible before you debug it

  • Pin the Node major in setup-node and in engines. A bundler that resolves native bindings will pick a different prebuilt binary across majors.
  • Delete node_modules locally and reinstall from the lockfile before concluding the runner is at fault; most "works locally" reports are stale local state.
  • Set CI=true locally to reproduce. Several toolchains change behaviour under it, including treating warnings as errors.
  • Exit code 137 is an out-of-memory kill. Raise --max-old-space-size or move to a larger runner rather than searching the bundler config.

How to prevent it

  • Exclude node_modules from source-map-loader.
  • Use ignoreWarnings to filter known third-party source-map noise.
  • Decide deliberately whether CI should treat warnings as errors.

Frequently asked questions

What causes Webpack source-map-loader "Failed to parse source map"?
There are 2 common causes: a dependency ships a bad sourcemappingurl and ci treats warnings as errors. The published package references a source map (//# sourceMappingURL=...) that was not included in the npm tarball, so source-map-loader cannot find it.
How do I fix Webpack source-map-loader "Failed to parse source map"?
There are 2 fixes depending on which cause you have: exclude node_modules from source-map-loader and ignore the specific warning (cra). Work through them in order, since the first is the most common.
What does Webpack source-map-loader "Failed to parse source map" actually mean?
The build floods with Failed to parse source map from '<node_modules path>': Error: ENOENT warnings, and in CI (warnings-as-errors) the build then fails.
How do I stop Webpack source-map-loader "Failed to parse source map" happening again?
Exclude node_modules from source-map-loader. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card