Can I hide or silence “npm ERR!” output when using npm run script?

后端 未结 5 1404
余生分开走
余生分开走 2021-01-03 18:04

I\'m using npm run script to do tasks such as \"build\" and \"test\".

For example, my package.json looks like the following:

{
  \"name\         


        
5条回答
  •  攒了一身酷
    2021-01-03 18:16

    You have to use npm run build --silent.

    This isn't documented in npm help, npm help run, or anything else obvious, but with some searching on the internet you can find out that apparently it is documented in npm help 7 config. You can also use the loglevel option in .npmrc.

    The --silent (short: -s) option suppresses:

    • The two lines beginning with > that say what command you're running.
    • npm ERR! errors.
    • Creating an npm-debug.log if there's an error.

    Note: using npm scripts to run other npm scripts may require you to use --silent more than once. Example package.json:

    {
      . . .
      "scripts": {
        "compile": "tsc",
        "minify": "uglifyjs --some --options",
        "build": "npm run compile && npm run minify"
      }
    }
    

    If you do npm run build and TypeScript finds an error, then you'll get the npm ERR! from both scripts. To suppress them, you have to change the build script to npm run compile --silent && npm run minify and run it with npm run build --silent.

提交回复
热议问题