Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 604
tomwang1013 Avatar asked May 13 '20 06:05

tomwang1013


People also ask

How do I enable source maps in Chrome?

Browser support To enable source maps in Google Chrome, go to Developer Tools, click the little cog icon, and then make sure that “Enable Javascript source maps” is checked. That's it.

What is Sourcemappingurl?

The SourceMap HTTP response header links generated code to a source map, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger.

What is source map loader?

source-map-loader allows webpack to maintain source map data continuity across libraries so ease of debugging is preserved. The source-map-loader will extract from any JavaScript file, including those in the node_modules directory.

How to fix'DevTools failed to load sourcemap''status code 404'error?

How to fix 'DevTools failed to load SourceMap' 'status code 404, net::ERR_UNKNOWN_URL_SCHEME' issue. If playback doesn't begin shortly, try restarting your device. Videos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.

Why can't I load the source map from node_modules?

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.

Why are source maps difficult to debug?

Such scripts are difficult to debug than the original source code. A source map is a file that maps from the transformed source to the original source, enabling the browser to reconstruct the original source and present the reconstructed original to the debugger.

How do I fix the sourcemap error in the development tools?

Turn off the extension by sliding the switch to the left. Reload the page that you were using the Development Tools on. Check if any of the "SourceMap" error messages disappeared. If any did, then that extension was causing those messages. Otherwise, that extension can be turned back on. After determining which extensions caused the issue either:


Video Answer


6 Answers

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"
  }),
...
],
like image 63
Rokas Lengvenis Avatar answered Oct 23 '22 06:10

Rokas Lengvenis


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

like image 37
Phương Nam Avatar answered Oct 23 '22 04:10

Phương Nam


  devtool: "eval-cheap-source-map"

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

like image 26
Almedin Hodžić Avatar answered Oct 23 '22 04:10

Almedin Hodžić


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

like image 14
Nafis Avatar answered Oct 23 '22 04:10

Nafis


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

like image 3
Marty Kane Avatar answered Oct 23 '22 04:10

Marty Kane


Add below line to your weback config

  devtool: 'source-map ./src',
like image 2
n9n Avatar answered Oct 23 '22 05:10

n9n