错误 TS2507:类型 'typeof Tapable' 不是构造函数类型

error TS2507: Type 'typeof Tapable' is not a constructor function type

我创建了一个私有的 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"
  }
}

这是来自另一个 server nodeJs 存储库的示例 package.json,它依赖于 lib:

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"
  }
}

server nodeJs 存储库中 运行 yarn install 时,我收到此错误:

$ 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\.tmpf8bdfc66f08780f32df98202058b430.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\_logs19-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 issue,建议添加 @types/tapable@0.2.5。我已经尝试将它添加到库和主仓库中,但问题仍然存在。

使用 npm installyarn install 都会发生这种情况。

如有任何帮助,我们将不胜感激。

TS skipLibCheck 编译器选项可能有帮助

在其他开发计算机上成功 yarn install 后,我认为问题出在我的环境中。

我已将 Node.jsnpmyarn 更新到最新版本。删除了所有全局包。已清除 npm & yarn 缓存。什么都没用。

最后,我发现我有 ~/node_modules 目录,其中包含 tapable(以及其他一些软件包)。我完全删除了那个目录,现在一切正常。