0

我正在开发一个电子应用程序。我已经dotenv-webpack在 webpack 配置中添加了插件,但是当我尝试构建它时,我收到来自 Terser 的错误。此外,如果我对 TerserPlugin 配置进行评论,错误仍然会出现。

Terser 错误分配无效。

import TerserPlugin from 'terser-webpack-plugin';
import Dotenv from 'dotenv-webpack';

export default {
  // ...
  optimization: {
    minimizer: [
      new TerserPlugin({
        parallel: true,
      }),
    ],
  },

  plugins: [
    // ...
    new Dotenv({
      path: path.join(__dirname, '../../.env'), // The path is correct
      systemvars: true,
    }),
  ]
}
4

1 回答 1

0

它是由于debug包装造成的。 node.js文件有以下代码:

function save(namespaces) {
    if (namespaces) {
        process.env.DEBUG = namespaces;
    } else {
        // If you set a process.env field to null or undefined, it gets cast to the
        // string 'null' or 'undefined'. Just delete instead.
        delete process.env.DEBUG;
    }
}

由 Dotenv 插件替换为后续行:

function save(namespaces) {
    if (namespaces) {
       "true" = namespaces;
    }  else {
        // If you set a process.env field to null or undefined, it gets cast to the
        // string 'null' or 'undefined'. Just delete instead.
        delete "true;
    }
于 2021-07-21T11:53:22.810 回答