• 在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 g2-webpack-starter-demo pm-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

  • 相关阅读:
    Cheatsheet: 2010 05.25 ~ 05.31
    Cheatsheet: 2010 07.01 ~ 07.08
    Cheatsheet: 2010 07.22 ~ 07.31
    Cheatsheet: 2010 06.01 ~ 06.07
    Cheatsheet: 2010 05.11 ~ 05.17
    Cheatsheet: 2010 06.08 ~ 06.15
    Cheatsheet: 2010 06.16 ~ 06.22
    Cheatsheet: 2010 06.23 ~ 06.30
    2020.7.20第十五天
    2020.7.19第十四天
  • 原文地址:https://www.cnblogs.com/liuyt/p/5677193.html
Copyright © 2020-2023  润新知