gpt4 book ai didi

npm - 使用 npm run 脚本时可以隐藏或静音 "npm ERR!"输出吗?

转载 作者:行者123 更新时间:2023-12-02 09:19:59 27 4
gpt4 key购买 nike

我正在使用npm run script执行“构建”和“测试”等任务。

例如,我的 package.json 如下所示:

{
"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 并且成功时,输出如下:

> fulfillment-service@1.0.0 build d:\code\fulfillment-service
> tsc

当我运行 npm run build 并且失败时,输出如下:

> 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

这会用无用的信息填充整个控制台,我必须滚动到顶部才能查看失败的原因。

在开发过程中是否有办法隐藏/静音以 npm ERR! 开头的行?

最佳答案

您必须使用npm run build --silent

这没有记录在 npm helpnpm help run 或其他任何明显的内容中,但是通过在互联网上进行一些搜索,您可以发现 apparently它记录在 npm help 7 config 中。您还可以使用loglevel .npmrc 中的选项。

--silent(简称:-s)选项抑制:

  • > 开头的两行表示您正在运行的命令。
  • npm ERR! 错误。
  • 如果出现错误,则创建 npm-debug.log
<小时/>

注意:使用 npm 脚本运行其他 npm 脚本可能需要您多次使用 --silent 。示例package.json:

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

如果您执行npm run build并且TypeScript发现错误,那么您将从两个脚本中获得npm ERR!。要抑制它们,您必须将构建脚本更改为 npm runco​​mpile --silent && npm run minify 使用 npm run build --silent< 运行它.

关于npm - 使用 npm run 脚本时可以隐藏或静音 "npm ERR!"输出吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38084112/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com