2016-06-28 2 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 helpnpm help run 문서화되지 않았거나 분명 아무것도 다른,하지만 인터넷에서 몇 가지 검색 당신은이 npm help 7 config에 설명되어 있습니다 apparently 것을 알 수 있습니다. .npmrcloglevel 옵션을 사용할 수도 있습니다.

--silent (짧은 : -s) 옵션을 억제 : 실행중인 명령 무슨 말을 >로 시작

  • 두 라인.
  • npm ERR! 오류가 발생했습니다.
  • 오류가있는 경우 npm-debug.log 생성.

참고 : 한 번 이상 --silent 이상을 사용해야하는 다른 NPM 스크립트를 실행하는 NPM 스크립트를 사용하여. 예 package.json : 당신이 npm run build을하고 타이프 라이터가 오류를 발견하면

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

, 당신은 npm ERR!에서 모두 스크립트를 얻을 것이다. 이를 억제하려면 빌드 스크립트를 npm run compile --silent && npm run minify으로 변경하고 npm run build --silent으로 실행해야합니다.

0

는 NPM 출원에 문제가 있습니다 : 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 

실행중인 바이너리 중 하나가 표준 오류에 기록 발생하면, 그 억제됩니다 대부분의 경우에 작동하는 것 같다 다른 방법이있다. 하지만 대부분의 노드 물건은 stdout에 쓰므로 문제가되지 않습니다.

물론 출력 리디렉션을 지원하는 셸 환경에서만 작동합니다.

관련 문제