我创建了一个私有的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"
}
}
这是另一个依赖于lib的server
nodeJs的示例server
:
package.json:
{
"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"
}
}
在yarn install
nodeJs中运行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.
我找到了这个GitHub问题,它建议添加@types/tapable@0.2.5
。我试着把它添加到图书馆和主要回购程序中,但问题仍然存在。
使用npm install
和yarn install
都会发生这种情况。
任何帮助都将不胜感激。
发布于 2019-04-12 21:29:03
在其他开发计算机上成功使用yarn install
之后,我认为问题出在我的环境中。
我已将Node.js
、npm
、yarn
更新为最新版本。删除了所有的全局包。清除了npm
和yarn
缓存。什么都没用。
最后,我发现我的~/node_modules
dir里面有tapable
(以及其他几个包)。我把它完全删除了,现在一切都正常了。
发布于 2019-04-10 19:50:22
TS skipLibCheck
编译器选项可以帮助
https://stackoverflow.com/questions/55617141
复制相似问题