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

眉间皱痕 提交于 2020-08-07 04:05:53

问题


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

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

回答1:


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"
  }),
...
],



回答2:


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



来源:https://stackoverflow.com/questions/61767538/devtools-failed-to-load-sourcemap-for-webpack-node-modules-js-map-http-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!