Webpack warns Failed to parse source map from a dependency
Failed to parse source mapShort 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.
Fix it fast
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.json2Match what you see, then jump to its fix
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.js2Fix
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 productionConfirmed by github.com
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.js2Fix
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 productionConfirmed by github.com
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.js2Fix
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 productionConfirmed by webpack.js.org
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix