webpack打包提示ERROR in main.js from Terser Invalid assignment

下面是我的webpack.config.js配置文件代码

const path = require('path')
const webpack = require('webpack')
const npm_package = require('./package.json')
const _externals = require('externals-dependencies')
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
function  resolve(dir) {
    return  path.join(__dirname, '..', dir)
}
module.exports = {
    mode: 'production',
    devtool: 'source-map',
    cache: true,
    entry: ['babel-polyfill', './src/app.js'],
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].js',
        publicPath: '/dist',
        chunkFilename: 'js/[id].chunk.js'
   },
    resolve: {
    extensions: ['.js', '.json'],
    alias: npm_package._moduleAliases || {
        '@':  resolve('src')
    },
    modules: npm_package._moduleDirectories || []
},
target: 'node',
externals: [_externals(), nodeExternals()],
context: __dirname,
node: {
    console: true,
    global: true,
    process: true,
    Buffer: true,
    __filename: true,
    __dirname: true,
    setImmediate: true,
    path: true
},
module: {
    rules: [{
        test: /\.js/,
        exclude: /node_modules/,
        use: {
            loader: 'babel-loader',
            options: {
                cacheDirectory: true,
                presets:  ['es2015', 'env'],
                plugins:  ['transform-runtime', 'transform-object-rest-spread']
           }
        }
    }]
},
plugins: [
    new webpack.DefinePlugin({
        'process.env': {
        NODE_ENV:  '"production"'
    }
    })
    // new CopyWebpackPlugin(\[{
    // from: path.resolve(__dirname, '/config/config.js'),
    // toType: 'file'
    // },{
    // from: path.resolve(__dirname, '/config/baseConfig.js'),
    // toType: 'file'
    // }])
    ]
}

打包后就出现如下图错误
image.png

阅读 10.1k
3 个回答

感谢问题找到了,是因为在第三行,我写了个process.env.NODE_ENV='prodction',
我想问一下,这是为什么呀?
image.png

image.png
这里说的是赋值无效,检查你的代码,config.js的第3行和main的第568行,看看有没有赋值问题,比如if语句里面写了==写成了=;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏