22

I have the following package.json file and I am building using webpack:

{
  "name": "web",
  "private": true,
  "scripts": {
    "build": "webpack --config webpack.config.js --mode development"
  },
  "devDependencies": {
    "webpack": "4.21.0",
    "webpack-cli": "3.1.2"
  },
  "dependencies": {
    "jquery": "3.4.1"
  }
}

How can I pass a parameter when using npm run build to use verbose so I can see build errors?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481

3 Answers3

32

Try the following:

npm run build --verbose

(you can pass any parameter via npm run <command> after --).

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
h3yduck
  • 1,571
  • 14
  • 14
  • 11
    We know from the official documentation that build does not have a verbose argument, the answer is wrong. I don't know why this answer is marked as correct. – goodmice Oct 27 '22 at 11:57
  • 2
    I can validate that this answer is wrong for Webpack 5, it fails the build on – Ville Dec 12 '22 at 13:49
  • i see `--verbose` in `webpack -h`, but is that `--verbose` passed to npm or webpack? – Dee Mar 03 '23 at 08:18
  • 1
    Webpack build fails for me with --verbose – Chandan Mar 30 '23 at 00:07
4

You can set the output details level using the stats prop in the webpack config file

module.exports = { stats: 'verbose',};

https://webpack.js.org/configuration/stats/

MadJoRR
  • 240
  • 2
  • 9
3

To be more clear with regards to the first answer, using npm run build --verbose does increase the log level of the npm process, as noted here https://docs.npmjs.com/cli/v8/using-npm/logging. This does not necessarily bump any log level in the Webpack process itself.

The first answer would incur additional logging for the npm process. The parenthetical note is slightly misleading -- if you want to pass a parameter to an npm script to pass to the underlying scripts, you need to add a primary "--". So, while that answer does increase npm logging, it doesn't necessarily alter the webpack logging verbosity.

For example, if you have a linter scripts in npm:

"jest-preview": "jest-preview",
"lint": "eslint ./src",
"build": "webpack --config webpack.config.js --mode development"

If you want to utilize the "--fix" parameter to pass to eslint, you would run this npm script as:

npm run lint -- --fix

As can be seen on https://webpack.js.org/api/cli/, there is no --verbose option for build in webpack-cli. There are some facilities for log output verbosity configuration for the loaders and plugins that can be implemented in the webpack config. I would check that documentation for further information.

intafon
  • 166
  • 2