我如何调试这个 Webpack 错误 - 来自 Terser 的 bundle.js 中的错误 [英] How can I debug this Webpack error - ERROR in bundle.js from Terser

查看:59
本文介绍了我如何调试这个 Webpack 错误 - 来自 Terser 的 bundle.js 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 webpack 来捆绑 Node JS 项目,因为它在最小化代码大小等方面提供了好处,并将所有依赖项捆绑在一起.

I am trying to use webpack to bundle up a Node JS project, for the benefits it offers in terms of minimising the size of the code etc. and bundling together all of the dependencies.

我的 webpack 作业失败并出现以下错误:

My webpack job is failing with the following error:

ERROR in bundle.js from Terser
Invalid function parameter [bundle.js:186393,23]

这是我的 webpack.config 文件:

This is my webpack.config file:

const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
    target: "node",
    mode: "production",
    entry: {
        app: ["./src/vitaq_client.js"]
    },
    // https://webpack.js.org/configuration/node/
    // node: {
    //     global: false,
    //     __filename: true,
    //     __dirname: true,
    // },
    module: {
        // https://github.com/ivan-aksamentov/reactlandia-bolerplate-lite/issues/5#issuecomment-413306341
        exprContextCritical: false,
        rules: [
            {
                test: /\.node$/,
                use: 'node-loader'
            },
            {
                test: /coffee/,
                use: 'node-loader'
            },
            {
                test: /\.coffee$/,
                use: [ 'coffee-loader' ]
            },
            // {
            //     test: /\.map$/,
            //     use: ["source-map-loader"],
            //     enforce: "pre"
            // },
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
    ],
    output: {
        path: path.resolve(__dirname, "./build"),
        filename: "bundle.js"
    },
};

这是我用来运行它的命令:

and this is the command I am using to run it:

webpack --config webpack.config.js

从我所做的搜索来看,似乎有一个用于代码压缩的 Terser 插件,但是正如您从我的配置文件中看到的,我没有加载该插件,所以 webpack 默认使用该插件吗?如果不是,我怎么会从 Terser 收到错误消息?

From the searching I have done it seems that there is a Terser plugin for code minification, but as you can see from my config file I am not loading that plugin, so does webpack use that plugin by default? If not how could I be getting an error from Terser ?

如果我在配置文件中将模式设置为开发",那么我不会遇到问题,但我怀疑这是因为开发代码不会被缩小.

If I set the mode to "development" in the config file, then I do not get the problem, but I suspect that is because development code would not get minified.

对于我如何着手调试这个问题,我有点困惑——有没有办法从 Webpack 获得更多输出.我曾尝试使用 --json >当我调用 webpack 时,compile-stats.json 命令行参数,但是我得到了一个巨大的输出文件 (43Mb),我在所有这些文件中找不到任何帮助.

I am a bit stuck as to how I set about debugging this problem - are there ways of getting more output from Webpack. I have tried using the --json > compilation-stats.json command line argument when I invoke webpack, but I get a huge output file (43Mb) and I can't find anything in all of that to help.

如有任何建议,我们将不胜感激.

Any suggestions would be gratefully received.

推荐答案

这是一个赋值错误,你在 bundle.js 的给定行有一个无效的函数参数.

This is an error with assignment where you have an invalid function parameter at the given line of bundle.js.

你可以通过不最小化 webpack 构建来解决这个问题:

You can solve this by not minimizing the webpack build:

    optimization: {
        minimize: false
    }

然后从错误输出中找到分配错误行,在非缩小包中.

Then finding the assignment error line from the error output, in the non minified bundle.

Invalid function parameter [bundle.js:186393,23]

希望这对其他人有帮助.

Hope this helps someone else.

这篇关于我如何调试这个 Webpack 错误 - 来自 Terser 的 bundle.js 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆