Cha*_*man 4 types node.js npm typescript
我正在使用 node/typescript 为 Discord 开发一个机器人。当我在源代码上运行打字稿编译器时,出现此错误:
node_modules/@types/readable-stream/index.d.ts(13,15): error TS2417: Class static side 'typeof _Readable' incorrectly extends base class static side 'typeof Readable'.
The types of 'Stream.Readable.Writable' are incompatible between these types.
Type 'typeof _Readable.Writable' is not assignable to type 'typeof import("stream").Writable'.
Types of parameters 'options' and 'opts' are incompatible.
Type 'import("stream").WritableOptions' is not assignable to type '_Readable.WritableOptions'.
Type 'WritableOptions' is not assignable to type 'WritableStateOptions'.
Types of property 'defaultEncoding' are incompatible.
Type 'string' is not assignable to type 'BufferEncoding'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! Shattered-Star@1.0.0 tsc: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the Shattered-Star@1.0.0 tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)
我试过重新安装,@types/node因为这似乎是它来自的模块,但这并没有引起任何变化。据我所知,我的源代码甚至都没有使用readable-streams子模块。事实上,删除它解决了我的问题——我只想知道到底发生了什么。这是我tsconfig.json的以防万一我在那里遗漏了一些东西:
{
"compilerOptions": {
"target": "es6",
"outDir": "built/",
"moduleResolution": "Node"
},
"include": [
"./bot/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
我将不胜感激。希望我不是唯一遇到这种情况的人。谢谢!
小智 7
我最近遇到了这个问题。这似乎是@types/readable-stream(2.3.6)的最后一个版本和您的node.
你可以在你的 yarn.lock / package-lock.json 中检查这个包在这个版本中的存在
似乎@types/readable-stream@2.3.6是node >= 14-compatible@types/readable-stream@2.3.5而是node < 14-compatible
我是如何在我的环境中修复它的node < 14:
yarn add -D --exact @types/readable-stream@2.3.5
Run Code Online (Sandbox Code Playgroud)
或者使用 npm:
npm i -D -E @types/readable-stream@2.3.5
Run Code Online (Sandbox Code Playgroud)
这会覆盖@types/readable-stream包版本并2.3.5通过添加"@types/readable-stream": "2.3.5"你的 package.json devDependencies明确设置为固定版本
我猜(但我没有测试过)我遇到了同样的问题并且你的node版本是>= 14,你可能必须对2.3.6版本执行相同的操作@types/readable-stream
来源:https : //github.com/DefinitelyTyped/DefinitelyTyped/issues/44828
| 归档时间: |
|
| 查看次数: |
2678 次 |
| 最近记录: |