Error: Cannot find module 'tslint/lib/lint' when trying to extend tslint-microsoft-contrib

Error: Cannot find module 'tslint/lib/lint' when trying to extend tslint-microsoft-contrib

这是我们的环境

> \node_modules\.bin\tslint --version
4.0.1

> npm install --save-dev tslint-microsoft-contrib
`-- tslint-microsoft-contrib@2.0.13

这是我们的 tslint.json 配置。

{
    "extends": [
        "./node_modules/tslint-microsoft-contrib/tslint.json"
    ]
}

这就是我们 运行 我们的本地 tslint 使用该配置时发生的情况。

> node_modules\.bin\tslint --config .\tslint.json --project .\tsconfig.json
module.js:471
throw err;
^

Error: Cannot find module 'tslint/lib/lint'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\myApp\node_modules\tslint-microsoft-contrib\insecureRandomRule.js:7:12)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)     

我们如何 运行 tslint 在扩展 tslint-microsoft-contrib 的配置上?

您需要降级到 tslint 3.x.x,tslint-microsoft-contrib 尚不支持 tslint 4,PR #314 应该解决这个问题,PR 看起来已经完成,但测试需要 grunt -tslint 也将升级以支持 tslint 4。同时,您可以继续使用 tslint@3