Webpack Script Run Issue [webpack-cli] Error: Unknown option '--env.development'

I am trying to run the application after upgrading webpack4 to webpack5, I also upgrade the node version to 18. Here is what I am getting...

[webpack-cli] Error: Unknown option '--env.development'
[webpack-cli] Run 'webpack --help' to see available commands and options

Here is my package.json file

"scripts": {
    "start": "webpack-dev-server --env.development",
    "watch": "webpack --watch",
    "build-production": "webpack --env.production --env.NODE_ENV=production ",
    "build-staging": "webpack --env.production --env.NODE_ENV=staging ",
    "build-development": "webpack --env.production --env.NODE_ENV=development ",
    "test": "jest --maxWorkers=4 --logHeapUsage",
    "lint:report": "eslint -f checkstyle -o ./eslint_report/report.xml --ext .js,.vue .",
    "lint:fix": "eslint --ext .js,.vue --fix .",
    "lint": "eslint . --ext .js,.vue",
    "format": "prettier -w .",
    "prepare": "husky install"
  },
 "webpack": "^5.74.0",
    "webpack-cli": "^4.10.0",
    "webpack-dev-server": "^4.11.1"

What is actually going wrong?

Upvotes: 4

Views: 7853

Answers (1)

Martin Lisowski
Martin Lisowski

Reputation: 687

There are breaking changes from webpack 4 to webpack 5, hence the major version bump. In your case the command line option for environment variables has changed, see https://webpack.js.org/api/cli/#environment-options So you need to remove the dots after --env like --env NODE_ENV=production instead of --env.NODE_ENV=production

Expect more incompatibilities in the webpack configuration file.

Upvotes: 7

Related Questions