webpack + babel loader source map references empty file

眉间皱痕 提交于 2019-11-30 11:39:09

Babel introduced a different sourcemap format here and Webpack didn't handle it correctly.
The fix was merged in this PR, and released in Webpack 1.14.0.

This also just started happening to me today,

I'm not sure what the root of the problem is, but switching devtool from cheap-module-eval-source-map to sourceMap has fixed the problem for the time being.

Quite late to this thread. But, thought this is going to help future readers. I am just practicing ES6 + Babel + Webpack combination and came across this video which explains on setting up develop environment for ES6/ES2015 using Babel and Webpack.

https://www.youtube.com/watch?v=wy3Pou3Vo04

I tried exactly as mentioned in that video and worked for me with no issues. In case if anyone is having trouble with source code/video:

Package.json

{
  ...
  "devDependencies": {
    "babel-core": "^6.14.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.14.0",
    "webpack": "^1.13.2"
  },
  "dependencies": {
    "jquery": "^3.1.0"
  }
}

Message.js

export default class Message {
    show(){
        alert("Hello world!");
    }
}

app.js

import msg from './Message.js'
import $ from 'jquery'

$(function(){
    $("#ShowBtn").on("click", function(){
        var o = new msg();
        o.show();   
    });
});

index.htm

<html>
<head>
	<title></title>
	<script type="text/javascript" src="build/app.all.js"></script>
</head>
<body>
	<button id="ShowBtn">Show</button>
</body>
</html>

webpack.config.js

var path = require('path');
var webpack = require('webpack');

module.exports = {
    devtool: 'source-map',
    entry: ['./src/app.js'],
    output: {
        path: './build',
        filename: 'app.all.js'
    },
    module:{
        loaders:[{
            test: /\.js$/,
            include: path.resolve(__dirname, "src"),
            loader: 'babel-loader',
            query:{
                presets: ['es2015']
            }
        }]
    },
    watch: true //optional
};

The only one thing I added in the above source code for proper source maps is "devtool: 'source-map'" in webpack.config.js (of course, not mentioned in that video).

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