在package.json中配置Script執行npm run tslint報錯問題


今天在學習tslint的時候,按照git clone下angular2-webpack-starter的代碼執行npm run lint時,雖然代碼進行了檢測,但檢測完成后npm始終報錯,

//package.json 報錯的配置
  
"scripts": {
    "lint": "tslint \"src/**/*.ts\"",
  },
//返回的錯誤

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Carter\\AppData\\Roaming\\npm\\node_modules\\cnpm\\node_modules\\npm\\bin\\npm-cli.js" 
"--userconfig=C:\\Users\\Carter\\.cnpmrc" "--disturl=https://npm.taobao.org/mirrors/node" "--registry=https://registry.npm.taobao.org" "run" "lint" npm ERR! node v4.2.4 npm ERR! npm v3.8.9 npm ERR! code ELIFECYCLE npm ERR! ng2-webpack-starter-demo@1.0.0 lint: `tslint "src/**/*.ts"` npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the ng2-webpack-starter-demo@1.0.0 lint script 'tslint "src/**/*.ts"'. 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 ng2-webpack-starter-demo package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! tslint "src/**/*.ts" npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs ng2-webpack-starter-demo npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls ng2-webpack-starter-demo npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! D:\GitHub\ng2-webpack-starter-demo\npm-debug.log

 

經過google一番,終於找到解決方案

原因是因為,當npm執行script完成時,script需要返回一個狀態為0的code,npm才會正常退出,

因為tslint執行完成后檢測到有錯誤,所以沒有返回code 0,所以導致npm構建出現了錯誤。

tslint 修復后給了一個參數 --force,即使檢測的代碼中有錯誤,也強制返回code 0。

//package.json 修復錯誤
  
"scripts": {
    "lint": "tslint \"src/**/*.ts\" --force",
  },

 

資料:

https://github.com/palantir/tslint/issues/1057

https://github.com/palantir/tslint/issues/1012

https://github.com/palantir/tslint/issues/1059


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM