我创建了一个私有TypeScript库,可用于我拥有的其他几个项目中。其目的是保存共享的TS模型。
我将仅简化库回购的重要部分:
index.ts:
export interface IApp { ... }
package.json:
{
"name": "my-lib",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"prepare": "npm run build"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.6",
"@types/node": "^11.13.2",
"chai": "^4.2.0",
"mocha": "^6.1.2",
"ts-node": "^8.0.3",
"typescript": "^3.4.3"
}
}
这是另一个package.json
依赖库的server
节点回购中的示例{
"name": "my-server",
"scripts": {
"start": "ts-node-dev --respawn --transpileOnly ./src/index.ts",
},
"dependencies": {
"my-lib": "git+ssh://git@gitlab.com/me/my-lib.git",
"ts-node-dev": "^1.0.0-pre.32",
},
"devDependencies": {
"@types/node": "^11.13.0",
"typescript": "^3.4.2"
}
}
:
package.json:
yarn install
在server
节点回购中运行$ yarn install
yarn install v1.15.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
$ npm run build
> my-lib@1.0.0 build C:\Users\Me\AppData\Local\Yarn\Cache\v4\.tmp\1f8bdfc66f08780f32df98202058b430.f3e8cc10b42f696133e0e0e207296fcbbd45ba0e.prepare
> tsc
../../../../../../../node_modules/@types/webpack/index.d.ts:529:28 - error TS2507: Type 'typeof Tapable' is not a constructor function type.
529 class Compiler extends Tapable implements ICompiler {
~~~~~~~
../../../../../../../node_modules/@types/webpack/index.d.ts:556:42 - error TS2507: Type 'typeof Tapable' is not a constructor function type.
556 abstract class MultiCompiler extends Tapable implements ICompiler {
~~~~~~~
Found 2 errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-lib@1.0.0 build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the my-lib@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Me\AppData\Roaming\npm-cache\_logs\2019-04-10T16_00_57_077Z-debug.log
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
时,出现此错误:
@types/tapable@0.2.5
我找到了这个GitHub issue,建议添加npm install
。我尝试将其添加到库和主仓库中,但问题仍然存在。
使用yarn install
和 pmd -d "C:\refactoring-toy-example" -f csv -R rulesets/java/unusedcode.xml
都会发生这种情况。
任何帮助将不胜感激。
答案 0 :(得分:0)
TS skipLibCheck
编译器选项可以帮助
答案 1 :(得分:0)
在另一台开发计算机上成功yarn install
后,我认为问题出在我的环境上。
我已将Node.js
,npm
,yarn
更新为最新版本。删除了所有全局软件包。已清除npm
和yarn
缓存。没有任何作用。
最后,我发现其中包含~/node_modules
的{{1}}目录(以及其他几个软件包)。我完全删除了该目录,现在一切正常。