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

3

50

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()
  ]

};
Gorham answered 25/8, 2016 at 13:14 Comment(3)
For me this only works with inline-source-map.Emogeneemollient
Any solution for this issue since then? I am hitting this with Electron (Chrome 86), Webpack 4 and inline-source-mapsTheophrastus
I stopped using web pack two years agoGorham
B
9

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

Bartholomeo answered 1/11, 2020 at 2:17 Comment(2)
I have tried to add the source map, but it does nothing. The source map validator is not working as well. I have tried with the mozilla library and is parsing the source map correctly.Villose
For people using NW.js, note that your source map path need to be a file:/// path if using the 'Add source map...' option.G
Z
1

If you're mapping to a workspace, that means you already have the source code. Including the source code in your source map is creating an unnecessary redundancy.

Use nosources-source-map instead.

Zippora answered 26/12, 2017 at 17:25 Comment(0)
M
0

The issue with external source maps was fixed in Chrome 52 but it looks like you've got your devtool set differently from mine, I use:

devtool: '#source-maps'

How are you building your source? If you're running with -d it will switch to inline source maps

Meri answered 3/9, 2016 at 12:1 Comment(4)
What's the difference when you add the #?Tribunal
The '#' controls the directive that does into the JS file. You can use '@' instead for older browsers:The original source map spec used '@', but this conflicted with 'conditional compilation' (which is activated with @cc_on) in IE<11, which runs code in comments, and would result in errors of the type:Meri
Not cryptic at allCedar
@ThomasGrainger Where is that documented? There is no mention of hashes or at-signs in the official docs: webpack.js.org/configuration/devtoolSabotage

© 2022 - 2024 — McMap. All rights reserved.