Webpack when run in terminal it gives an "error error: unknown option '-p'"

24,735

Looks like it was updated to be --mode production in a recent release.

https://github.com/webpack/webpack-cli/issues/1934

Share:
24,735
Synchro
Author by

Synchro

Updated on July 05, 2022

Comments

  • Synchro
    Synchro almost 2 years

    I wanted to run Webpack using npm run build but it gives an error in the terminal

    error: unknown option '-p'
    [webpack-cli] Run 'webpack --help' to see available commands and options
    npm ERR! code ELIFECYCLE
    C:\React Projects\Webpack\Project>
    

    enter image description here

    package.json

    {
      "name": "project",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "dependencies": {
        "webpack": "^5.11.1"
      },
      "devDependencies": {
        "webpack-cli": "^4.3.1"
      },
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "build": "webpack -p",
        "watch": "webpack --watch"
      },
      "author": "",
      "license": "ISC"
    }
    
  • Gerald Wichmann
    Gerald Wichmann over 3 years
    this worked for me. changed my webpack command in package.json from webpack -p --env production to webpack --mode production --env production