DevTools failed to load SourceMap for webpack:///node_modules//....js.map HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME

WebpackGoogle Chrome-Devtools

Webpack Problem Overview


I created a simple webpack based project to learn snabbdom. Everything was OK except that sourcemap failed loading:

enter image description here

I don't know whose issue(webpack, chrome) it is. Is there anyone who know it?

Reproduction steps:

git clone https://github.com/tomwang1013/snabbdom-test.git
npm install
npm run dev

Webpack Solutions


Solution 1 - Webpack

The source map you are trying to load is in node_modules and not part of webpack bundle. "If not extracted and processed into the source map of the webpack bundle, browsers may misinterpret source map data" ref. When app is loaded that causes "ERR_UNKNOWN_URL_SCHEME" in chrome dev tools console.

To process node_module source maps to webpack bundle, use source-map-loader loader. That will fix console warnings.

Add dependency to package.json:

"devDependencies": {
        "source-map-loader": "^1.0.0",
        ...
      }
 

Update webpack.config.js:

module: {
rules: [
  {
    test: /\.js$/,
    enforce: 'pre',
    use: ['source-map-loader'],
  },
],

},

To generate source maps for snabbdom-test project in general you can use SourceMapDevToolPlugin.

Update webpack.config.js:

const { SourceMapDevToolPlugin } = require("webpack");

plugins: [
  new SourceMapDevToolPlugin({
    filename: "[file].map"
  }),
...
],

Solution 2 - Webpack

Update webpack.config.js

module.exports = {
    // ...
    entry: {
      "app": "src/app.js"
    },
    output: {
      path: path.join(__dirname, 'dist'),
      filename: "[name].js",
      sourceMapFilename: "[name].js.map"
    },
    devtool: "source-map"
    // ...
};

Detailed in https://blog.sentry.io/2018/10/18/4-reasons-why-your-source-maps-are-broken

Solution 3 - Webpack

  devtool: "eval-cheap-source-map"

Add this to your webpack config and that's it.

Solution 4 - Webpack

Add devtool: 'eval-source-map' to top most level of webpack.config

Solution 5 - Webpack

If you want to just turn these off, you can use a webpack devtool option that ignores them. Detailed in my related question here

Solution 6 - Webpack

Add below line to your weback config

  devtool: 'source-map ./src',

Solution 7 - Webpack

@Phương Nam's answer will solve this error but even after setting filename: "[name].js", webpack may warn us regarding the conflict of multiple assets emitting to the same filename.

To fix above warning we can use SourceMapDevToolPlugin.

> This plugin enables more fine grained control of source map > generation. It is also enabled automatically by certain settings of > the devtool configuration option.

The following code to replace the configuration option devtool: inline-source-map with an equivalent custom plugin configuration:

    // ...
	plugins: [
		// ...
        new webpack.SourceMapDevToolPlugin({})
		// ...
	],
	devtool: false
    // ...

More examples of SourceMapDevToolPlugin

Solution 8 - Webpack

If nothing helps, try to use different webpack devtool mode.

Related the project for me working good this modes:

devtool: 'inline-source-map'

or

devtool: 'eval-cheap-source-map'	

or

devtool: 'eval-cheap-module-source-map'

or

devtool: 'inline-cheap-module-source-map'

Solution 9 - Webpack

If you're here and you're using Typescript, make sure you've got sourceMap: true in compilerOptions in your tsconfig.

Solution 10 - Webpack

Perhaps in each of those js files there is something like url commented: /*# sourceMappingURL=dsggdgdg.fdgdfn.dfg.map */

remove that

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiontomwang1013View Question on Stackoverflow
Solution 1 - WebpackRokas LengvenisView Answer on Stackoverflow
Solution 2 - WebpackPhương NamView Answer on Stackoverflow
Solution 3 - WebpackAlmedin HodžićView Answer on Stackoverflow
Solution 4 - WebpackNafisView Answer on Stackoverflow
Solution 5 - WebpackMarty KaneView Answer on Stackoverflow
Solution 6 - Webpackn9nView Answer on Stackoverflow
Solution 7 - WebpackchankruzeView Answer on Stackoverflow
Solution 8 - WebpackOleksandr PyrozhokView Answer on Stackoverflow
Solution 9 - WebpackRaph117View Answer on Stackoverflow
Solution 10 - WebpackCodeToLifeView Answer on Stackoverflow