'Vite and PostCSS issue, Invalid left-hand side in assignment

Everything was working fine, next day I'm getting an error Invalid left-hand side in assignment, the Chrome console tap was showing the error Invalid left-hand side in assignment a file with a name ${mod.url});` which is points to the source file and the code is:

var createContext = (ctx) => {
  ctx = Object.assign({
    cwd: process.cwd(),
    env: "development"
  }, ctx);
  if (!ctx.env) {
    "development" = "development"; // <-- pointing to this line
  }
  return ctx;
};

after checking I found that file is node_module/postcss-load-config/index.js, and code part:

    /**
 * Builds the Config Context
 *
 * @param  {Object} ctx Config Context
 *
 * @return {Object} Config Context
 */
const createContext = (ctx) => {
  /**
   * @type {Object}
   *
   * @prop {String} cwd=process.cwd() Config search start location
   * @prop {String} env=process.env.NODE_ENV Config Enviroment, will be set to `development` by `postcss-load-config` if `process.env.NODE_ENV` is `undefined`
   */
  ctx = Object.assign({
    cwd: process.cwd(),
    env: process.env.NODE_ENV
  }, ctx)

  if (!ctx.env) {
    process.env.NODE_ENV = 'development' // <-- HERE!
  }

  return ctx
}

I delete the directory node_module, delete the docker container and image, I did update the package.json dependencies and devDependencies, all of this did not solve the issue. Also, I remove the postcss, the result is the same. The site is developed with Vite, Vue and Tailwindcss latest version

For me this is a big challenge, so would someone kindly help me out of this?

Thanks,



Solution 1:[1]

I remove code, then it works

import { createLogger } from 'vite'
export createLogger

change this to

export const logger = console.log.bind(console)

I found that I used some node utils in broswer.

Solution 2:[2]

It seems that this happens when your code editor automatically adds import statements when you did not want it to. The same thing happened to me. I guess it could happen if you added an import statement on accident by yourself. I removed the erroneous import statement and now the error is gone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hang zou
Solution 2 McGrew