2016-06-28 12 views
8

मैं "निर्माण" और "परीक्षण" जैसे कार्यों को करने के लिए 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 चलाने के लिए और यह सफल होता है, उत्पादन निम्नलिखित है:

> [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 रन बिल्ड --सिलेंट – gcampbell

+2

रन स्क्रिप्ट के आउटपुट के बारे में एक मुद्दा खुला है। [एनपीएम/8821] देखें (https://github.com/npm/npm/issues/8821) – styfle

उत्तर

10

आपको npm run build --silent का उपयोग करना होगा।

यह कुछ और स्पष्ट npm help में प्रलेखित है नहीं, npm help run, या है, लेकिन इंटरनेट पर कुछ खोज के साथ आपको लगता है कि apparently यह npm help 7 config में प्रलेखित है पता कर सकते हैं। आप .npmrc में loglevel विकल्प का भी उपयोग कर सकते हैं।

--silent (लघु: -s) विकल्प को दबा:

  • दो > के साथ शुरुआत लाइनों का कहना है कि क्या आदेश आप चला रहे हैं।
  • npm ERR! त्रुटियां।
  • कोई त्रुटि होने पर npm-debug.log बनाना।

नोट: अन्य NPM स्क्रिप्ट को चलाने के लिए एक बार से अधिक --silent उपयोग करने के लिए आवश्यकता हो सकती है NPM स्क्रिप्ट का उपयोग। उदाहरण 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 के साथ चलाने के लिए बदलना होगा।

0

एक मुद्दा NPM को दायर की है: run-scripts are too noisy while used in development #8821

कि इस मुद्दे में चर्चा में (भी ऊपर एक टिप्पणी में उल्लेख किया है), लोगों की एक जोड़ी एक उपनाम बनाने जैसे उल्लेख किया है npr (--सिलेंट विकल्प gcampbell का उपयोग अपने उत्तर में वर्णित करता है)। हालांकि --silent कुछ एनपीएम प्रकार के मुद्दों को छिपा सकता है जैसे कि विकृत पैकेज.जेसन, यह अब के लिए एक उचित समाधान की तरह लगता है।कि चर्चा से

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

एक दूसरी बात जो, में देख लायक हो सकता है, हालांकि यह अभी तक एक और उपकरण है, जो एक yarnfacebook blog post पर वर्णन किया गया है है।

0

जैसा कि अन्य ने ध्यान दिया है, --silent के साथ समस्या आप सभी आउटपुट खो देते हैं।

npm run something 2>/dev/null 

बाइनरी आप चल रहे हैं में से एक को stderr करने के लिए लिखने के लिए होता है, तो वह दबा दिया जाएगा: वहाँ एक और तरीका है ज्यादातर मामलों के लिए काम करने के लिए लगता है कि है। लेकिन ज्यादातर नोड सामान stdout लिखते हैं, तो यह एक समस्या नहीं होनी चाहिए।

बेशक यह केवल एक शैल पर्यावरण में काम करेगा जो आउटपुट पुनर्निर्देशन का समर्थन करता है।

संबंधित मुद्दे