我可以隐藏或静音“npm ERR!"吗?使用 npm run 脚本时的输出? [英] Can I hide or silence "npm ERR!" output when using npm run script?
问题描述
我正在使用 npm run script 来执行诸如构建"和测试".
I'm using npm run script to do tasks such as "build" and "test".
例如,我的 package.json
如下所示:
For example, my package.json
looks like the following:
{
"name": "fulfillment-service",
"version": "1.0.0",
"description": "Endpoint for CRUD operations on fulfillment status",
"main": "src/server.js",
"scripts": {
"build": "tsc",
"test": "tape tests/*.js"
},
"dependencies": {},
"devDependencies": {
"typescript": "^1.8.10"
}
}
当我运行 npm run build
并且成功时,输出如下:
When I run npm run build
and it is successful, the output is the following:
> fulfillment-service@1.0.0 build d:\code\fulfillment-service
> tsc
当我运行 npm run build
并且失败时,输出如下:
When I run npm run build
and it fails, the output is the following:
> fulfillment-service@1.0.0 build d:\code\fulfillment-service
> tsc
src/server.ts(51,81): error TS2339: Property 'connection' does not exist on type 'IncomingMessage'.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! fulfillment-service@1.0.0 build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the fulfillment-service@1.0.0 build script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the fulfillment-service package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs fulfillment-service
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls fulfillment-service
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! d:\code\fulfillment-service\npm-debug.log
这会用无用的信息填满整个控制台,我必须滚动到顶部才能看到它失败的原因.
This fills the entire console with useless information, and I have to scroll to the top to see why it failed.
无论如何在开发过程中隐藏/静音以 npm ERR!
开头的行吗?
Is there anyway to hide/silence the lines that start with npm ERR!
during development?
推荐答案
必须使用npm run build --silent
.
You have to use npm run build --silent
.
这在 npm help
、npm help run
或任何其他明显的东西中没有记录,但是通过在互联网上进行一些搜索,您可以发现 显然它记录在 npm help 7 config
中.您还可以在 中使用
.loglevel
选项.npmrc
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
.
--silent
(简称:-s
)选项抑制:
- 以
>
开头的两行表示您正在运行的命令. npm ERR!
错误.- 如果出现错误,则创建
npm-debug.log
.
- 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.
注意:使用 npm 脚本运行其他 npm 脚本可能需要多次使用 --silent
.示例 package.json
:
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"
}
}
如果您执行 npm run build
并且 TypeScript 发现错误,那么您将从 两个 脚本中获得 npm ERR!
.要抑制它们,您必须将构建脚本更改为 npm run compile --silent &&npm run minify
and 使用 npm run build --silent
运行它.
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
.
这篇关于我可以隐藏或静音“npm ERR!"吗?使用 npm run 脚本时的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!