2016-06-28 5 views
8

私はnpm run scriptを使って "ビルド"や "テスト"などの作業を行っています。例えば「npm ERR!」を非表示にしたり、無音にすることはできますか? npm実行スクリプトを使用すると出力されますか?

、私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を実行し、それが成功すると、出力は以下の通りです:

> [email protected] build d:\code\fulfillment-service 
> tsc 

私はnpm run buildを実行し、それが失敗した場合出力は次のとおりです。

> [email protected] 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! [email protected] build: `tsc` 
npm ERR! Exit status 2 
npm ERR! 
npm ERR! Failed at the [email protected] 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!で始まる行を非表示/消音する方法はありますか?

+2

'npm run build --silent' – gcampbell

+2

実行スクリプトの出力に関する問題があります。 [npm/8821](https://github.com/npm/npm/issues/8821)を参照してください。 – styfle

答えて

10

npm run build --silentを使用する必要があります。

これはnpm help runnpm helpに記載、または明らかに何かが、いくつかは、インターネット上で検索すると、あなたはそれがnpm help 7 configに記載されてapparentlyことを見つけることができますされていません。 .npmrcloglevelオプションを使用することもできます。

--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を行うと、活字体がエラーを検出した場合、その後、あなたはnpm ERR!から両方スクリプトを取得します。それらを抑制するには、ビルドスクリプトをnpm run compile --silent && npm run minifyに変更して、npm run build --silentで実行する必要があります。 NPMに出願された問題があり

0

run-scripts are too noisy while used in development #8821(上記のコメントで述べた)

という問題での議論では、人々のカップルが、エイリアスなどを作成言及していますnpr(gcampbellはその答えに--silentオプションを使用しています)。 --silentは、不正なpackage.jsonなどのnpmタイプの問題を隠すことができますが、これは今のところ妥当な解決策のようです。

alias npr='npm run --silent $*' 

に探して価値があるかもしれないという議論からもうひとつ、それはまた別のツールであるものの、facebook blog postに記述されているyarnです。

0

他の人が指摘しているように、--silentの問題は、あなたが失うものですすべて出力です。

npm run something 2>/dev/null 

あなたが実行されているバイナリの1が標準エラー出力への書き込みに発生した場合、その後、それが抑制されます:ほとんどの場合のために働くように思われる別の方法があります。しかし、ほとんどのノードのものはstdoutに書き込むので、問題ではありません。

もちろん、出力リダイレクトをサポートするシェル環境でのみ動作します。

関連する問題