首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误TS2507:类型‘Tapable’不是构造函数类型

错误TS2507:类型‘Tapable’不是构造函数类型
EN

Stack Overflow用户
提问于 2019-04-10 16:16:43
回答 2查看 1.2K关注 0票数 1

我创建了一个私有的TypeScript库,用于我所拥有的其他几个项目。它的目的是保存共享的TS模型。

我将只简化库回购的重要部分:

index.ts:

代码语言:javascript
运行
复制
export interface IApp { ... }

package.json:

代码语言:javascript
运行
复制
{
  "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:

代码语言:javascript
运行
复制
{
  "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时,我将得到以下错误:

代码语言:javascript
运行
复制
$ 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 installyarn install都会发生这种情况。

任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-12 21:29:03

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

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

最后,我发现我的~/node_modules dir里面有tapable (以及其他几个包)。我把它完全删除了,现在一切都正常了。

票数 1
EN

Stack Overflow用户

发布于 2019-04-10 19:50:22

TS skipLibCheck编译器选项可以帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55617141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档