首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webpack-溪流打破@类型/webpack

webpack-溪流打破@类型/webpack
EN

Stack Overflow用户
提问于 2021-10-30 18:15:09
回答 1查看 340关注 0票数 1

我有一个用打字本建的文件。在我添加@types/webpack-stream之前,一切都是正常的,但由于某些原因,我得到了一个非常糟糕的错误:

代码语言:javascript
复制
node_modules/@types/webpack-stream/index.d.ts:23:24 - error TS2694: Namespace 'exports' has no exported member 'Compiler'.

23     callback?: webpack.Compiler.Handler,
                          ~~~~~~~~

node_modules/@types/webpack/index.d.ts:32:3 - error TS2305: Module '"tapable"' has no exported member 'Tapable'.

32   Tapable,
     ~~~~~~~

node_modules/@types/webpack/index.d.ts:1081:23 - error TS2707: Generic type 'SyncWaterfallHook<T, AdditionalOptions>' requires between 1 and 2 type arguments.

1081             resolver: SyncWaterfallHook;

...
[lots of other types not working here]
...

Found 90 errors.

下面是我的package.json

代码语言:javascript
复制
{
    "type": "module",
    "engines": {
        "node": "^16.12.0"
    },
    "scripts": {
        "dev": "tsc --watch",
        "gulp": "yarn gulp:build && yarn gulp:run",
        "gulp:build": "tsc --project gulp",
        "gulp:run": "gulp"
    },
    "dependencies": {
        "highlight.js": "^11.3.1"
    },
    "devDependencies": {
        "@babel/cli": "^7.15.7",
        "@babel/core": "^7.15.8",
        "@babel/plugin-transform-modules-amd": "^7.14.5",
        "@babel/plugin-transform-modules-commonjs": "^7.15.4",
        "@babel/plugin-transform-modules-systemjs": "^7.15.4",
        "@babel/plugin-transform-modules-umd": "^7.14.5",
        "@babel/preset-env": "^7.15.8",
        "@types/gulp": "^4.0.9",
        "@types/gulp-babel": "^6.1.30",
        "@types/gulp-if": "^0.0.34",
        "@types/gulp-rename": "^2.0.1",
        "@types/gulp-sourcemaps": "^0.0.35",
        "@types/gulp-terser": "^1.2.1",
        "@types/node": "^16.11.5",
        "@types/webpack-stream": "^3.2.12",
        "gulp": "^4.0.2",
        "gulp-babel": "^8.0.0",
        "gulp-cli": "^2.3.0",
        "gulp-if": "^3.0.0",
        "gulp-rename": "^2.0.0",
        "gulp-sourcemaps": "^3.0.0",
        "gulp-terser": "^2.1.0",
        "gulp-typescript": "^6.0.0-alpha.1",
        "rambda": "^6.9.0",
        "typescript": "^4.4.4",
        "webpack": "^5.61.0",
        "webpack-cli": "^4.9.1",
        "webpack-stream": "^7.0.0"
    }
}

在我添加该软件包之前,我考虑不添加它,但是TS对我尖叫,因为:

代码语言:javascript
复制
Could not find a declaration file for module 'webpack-stream'. '/node_modules/webpack-stream/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/webpack-stream` if it exists or add a new declaration (.d.ts) file containing `declare module 'webpack-stream';`ts(7016)`

但是当我加进去的时候,它就是不想工作。我尝试重新定义node_modules/@types/webpack-stream/index.d.ts:23:24中的第一个错误,看看是否是这样的:

代码语言:javascript
复制
    callback?: Parameters<webpack.Compiler["run"]>[0] | Parameters<webpack.Compiler["watch"]>[1]

哪个修复了的第一个错误,但其余的都停留在那里。我不知道该往哪里走,我可以在这里重新实现webpack-streams .

EN

回答 1

Stack Overflow用户

发布于 2021-10-30 18:47:15

找到解决办法了!

首先,进入@types/webpack-stream,在依赖项下得到@types/webpack@types/node

由于不同的原因,我已经安装了@types/node,所以:

@types/webpack-stream

  • added @types/webpack

  • added

  • 再次删除了@types @types/webpack-stream (以确保pnp解析为@types版本)

在此基础上,我有了保存gulpfile.tsgulpfile.ts目录,确保tsconfig.json具有以下内容:

代码语言:javascript
复制
{
    "compilerOptions": {
        "skipLibCheck": true
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69780936

复制
相关文章

相似问题

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