Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sourcemaps are detected in chrome but original source is not loaded, using webpack-2

When running an application that is built using webpack 2, sourcemaps are detected in chrome but original source is not loaded. I'm using webpack beta21.

These files used to be detected automatically, ie when a breakpoint was put in the the output from webpack js file, the source view would jump to the original source input to webpack. But now I am stuck with this screen: enter image description here

config:

var path = require("path"); var webpack = require("webpack"); var WebpackBuildNotifierPlugin = require('webpack-build-notifier');   const PATHS = {   app: path.join(__dirname, '../client'),   build: path.join(__dirname, '../public') };  module.exports = {     entry: {     app: PATHS.app + '/app.js'   },   output: {     path: PATHS.build,     filename: '[name].js'   },     devtool: "source-map",   module: {     loaders: [       {         test: /\.js?$/,         loader: 'babel-loader',         include: [           path.resolve(__dirname, 'client'),         ],         exclude: /node_modules/        },        {         test: /\.css/,         loader: "style!css"       }     ]   },   resolve: {     // you can now require('file') instead of require('file.js')     extensions: ['', '.js', '.json']   } ,   plugins: [     new WebpackBuildNotifierPlugin()   ]  }; 
like image 398
Nikos Avatar asked Aug 25 '16 13:08

Nikos


People also ask

What is source map detected?

A source map is a file that maps from the transformed source to the original source. Source map may help an attacker to read and debug Javascript.

What is Webpack Sourcemaps?

Webpack bundles multiple source files to one single bundle file. In some cases, there can be multiple bundle files. But in both cases, if there is an error in one of the source files, it is difficult to track it down from browser console. Source maps connect the bundle file with corresponding source files.


1 Answers

Generated files with source maps won't automatically redirect to their original files, because there's potentially a 1-to-many relationship.

If you see the message Source Map Detected, the original file should already appear on the side file tree or the file explorer via Crl + P. If you don't know the original file name, you can open the source map file itself.

  1. The source map path can be identified by a //# sourceMappingURL= comment or the X-SourceMap header:

    sourceMappingURL

  2. Open up the source map via url and look for the sources property for the original file name:

    source map file

  3. The original file should be visible in the sources panel:

    original file in sources panel

If you don't see the message Source Map Detected

You can manually add an external source map by right clicking and selecting Add Source Map:

Add source map

Additional Resources

  • If that still doesn't work, you can try a Source Map Validator
  • For webpack specifically, you can configure the devtool property
like image 78
KyleMit Avatar answered Oct 15 '22 06:10

KyleMit