Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Webpack warns Failed to parse source map from a dependency

ErrorFailed to parse source map

Short answer

This warning comes from source-map-loader, which reads the source map each file points to. When a file points to a map it cannot parse, webpack prints the warning but the build still works. Silence it with ignoreWarnings, or stop the loader from processing files in node_modules.

  • Applies to webpack 5, source-map-loader, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the loader is in your webpack config at all, and which files its rule matches.

    grep -rn "source-map-loader" webpack.config.js package.json
  2. 2Match what you see, then jump to its fix

    1. 1Failed to parse source map for a file inside node_modulesThe warning is harmless but noisy, and the loader reads dependency filesFix
    2. 2Warnings for many packages at onceThe loader rule matches every JavaScript fileFix
    3. 3You want to keep other warnings visibleOnly some warnings should be hiddenFix

What does the error look like?

  • Failed to parse source map

Cause 1 of 3

The warning is harmless but noisy, and the loader reads dependency files

1Check

The warning names a package you did not write. The build still finishes, so only the output is the problem.

grep -n "ignoreWarnings" webpack.config.js

2Fix

Add an ignoreWarnings entry that matches the message. This is the form the loader documents.

module.exports = {
  module: {
    rules: [
      { test: /\.js$/, enforce: "pre", use: ["source-map-loader"] },
    ],
  },
  ignoreWarnings: [/Failed to parse source map/],
};

3Verify

Run the build again and confirm that the warning is gone.

npx webpack --mode production

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The loader rule matches every JavaScript file

1Check

The rule has only test: /\.js$/, so webpack sends dependency files through the loader. Include and exclude conditions decide which files the loader sees.

grep -n -B2 -A4 "source-map-loader" webpack.config.js

2Fix

Limit the rule to your own source folder, or exclude node_modules.

{
  test: /\.js$/,
  enforce: "pre",
  exclude: /node_modules/,
  use: ["source-map-loader"],
}

3Verify

Build again. Warnings from dependencies should not appear.

npx webpack --mode production

Confirmed by github.com

Did this fix it?

Cause 3 of 3

Only some warnings should be hidden

1Check

ignoreWarnings accepts a regular expression, an object with module, file or message, or a function. A regular expression on the message alone hides every source-map warning.

grep -n -A6 "ignoreWarnings" webpack.config.js

2Fix

Use the object form to limit the filter to one package.

ignoreWarnings: [
  {
    module: /node_modules\/some-package/,
    message: /Failed to parse source map/,
  },
],

3Verify

Build again and check that warnings from other files still show.

npx webpack --mode production

Confirmed by webpack.js.org

Did this fix it?

How do I stop it coming back?

  • Keep the loader rule scoped to your own source folder unless you need maps of dependencies.
  • Use a message and module filter, not a function that returns true, so real warnings stay visible.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.