【问题标题】:Webpack + Babel Wrong Line Numbers in Stack TraceWebpack + Babel 堆栈跟踪中的错误行号
【发布时间】:2019-05-09 08:39:39
【问题描述】:

我正在使用 Webpack 和 Babel 构建一个应用程序。当应用程序遇到错误时,它会正确列出第一个错误的行号,但随后会显示每个后续步骤的缩小代码的行号。

我的 Webpack 配置如下,

const webpack = require('webpack');
const path = require('path');
module.exports = {
    module: {
        loaders: [
            {
                loader: "babel-loader",
                exclude: [
                    /(node_modules)/,
                ],
                query: {
                    presets: ['es2015','react'],
                    plugins: ['transform-object-rest-spread']
                }
            },
            {
                test:/\.less$/,
                exclude:'/node_modules',
                loader:"style!css!less"
            }
        ]
    },
    entry: {
        "index": ["./src/main"]
    },
    output: {
        path: path.resolve(__dirname, "public"),
        publicPath: "/assets",
        filename: "[name].bundle.js"
    },
    resolve: {
        extensions: ['', '.js', '.jsx'],
    },
    devServer: { inline: true },
    devtool: 'source-map'
};

【问题讨论】:

标签: javascript webpack babeljs


【解决方案1】:

为了从 webpack 生成的构建中进行调试,您需要了解更多关于 webpack 中的 'devtool' 设置的信息。这是官方文档的链接。 Webpack Devtool Configuration

现在遇到您的问题,您可以使用以下任一方法来导航到导致问题的原始代码。这只能使用源映射。

eval-inline-source-map //用于 DEV 构建

cheap-inline-module-source-map //用于 PROD 构建

例如,

{
   'devtool': 'cheap-inline-module-source-map'
}

【讨论】:

  • 我试过了,但行号仍然不正确
  • @CodeWhisperer 等等,你是在建议代码文件中的行号与生成的构建文件匹配吗?如果是这样,那么您还需要添加 webpack 运行时代码。
  • 官方文档没有cheap-inline-module-source-map,类似的inline-cheap-module-source-map不适合生产
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-10
  • 2017-06-25
  • 2018-09-19
  • 1970-01-01
相关资源
最近更新 更多