webpackdotenvterserelectron-react-boilerplate

dotenv-webpack and terser: error from Terser Invalid assignment


I'm working on an electron application. I've added the dotenv-webpack plugin in webpack config, but when I try to build it, I receive an error from Terser. Furthermore, if I comment on the TerserPlugin config, the error still appears.

Error from Terser Invalid assignment.

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,
    }),
  ]
}

Solution

  • It caused due to debug package. node.js file have follow code:

    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;
        }
    }
    

    Which replaced by follow lines, by Dotenv plugin:

    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;
        }