【问题标题】:dotenv-webpack and terser: error from Terser Invalid assignmentdotenv-webpack 和 terser:来自 Terser 无效分配的错误
【发布时间】:2021-09-28 18:19:01
【问题描述】:

我正在开发一个电子应用程序。我在 webpack 配置中添加了 dotenv-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,
    }),
  ]
}

【问题讨论】:

    标签: webpack dotenv terser electron-react-boilerplate


    【解决方案1】:

    这是由于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;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 2019-06-27
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多