Type ‘Server’ is not generic.

huangapple go评论144阅读模式
英文:

types/ws Type 'Server' is not generic

问题

突然出现了这个错误:

TypeScript: ./../../node_modules/@types/ws/index.d.ts:328:18
Type 'Server' is not generic.

Angular CLI: 13.3.11
Node: 16.13.2
包管理器: npm 8.1.2
操作系统: win32 x64

Angular: 13.4.0
... common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

包版本
@angular-devkit/architect 0.1303.11
@angular-devkit/build-angular 13.3.11
@angular-devkit/core 13.3.11
@angular-devkit/schematics 13.3.11
@angular/cli 13.3.11
@angular/pwa 13.3.11
@schematics/angular 13.3.11
rxjs 6.6.7
typescript 5.1.3

已尝试将 @types/ws 更新到版本 ^8.13.0,但未成功。

英文:

Suddenly getting this error:

TypeScript: ./..\..\node_modules\@types\ws\index.d.ts:328:18
       Type 'Server' is not generic.


Angular CLI: 13.3.11
Node: 16.13.2
Package Manager: npm 8.1.2
OS: win32 x64

Angular: 13.4.0
... common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package Version
@angular-devkit/architect 0.1303.11
@angular-devkit/build-angular 13.3.11
@angular-devkit/core 13.3.11
@angular-devkit/schematics 13.3.11
@angular/cli 13.3.11
@angular/pwa 13.3.11
@schematics/angular 13.3.11
rxjs 6.6.7
typescript 5.1.3

Already tried to update @types/ws to version ^8.13.0 with no success

答案1

得分: 7

我遇到了相同的问题
npm i @types/ws@8.5.4 对我有效。

英文:

I had the same issue
npm i @types/ws@8.5.4 worked for me.

答案2

得分: 3

我花了两天的时间来更新和降级 @types/node 和 @types/express。最后,我将我的 Angular 项目从 14 版本升级到了 15 版本,一切都再次完美运行。

英文:

I spent two days on this updating and downgrading @types/node and @types/express. In the end I updated my angular project from 14 to 15 and everything worked perfectly again.

答案3

得分: 3

我们在一个相对老的Angular项目的构建流程中遇到了这个问题。奇怪的是,自2023年6月以来,每隔一个构建就会失败。我成功解决了这个问题,如下所述。我的解决方案基于Salmin SkenderovicZen Donegan的答案下面所说的。

  1. 在packages.json中,我添加了这个依赖项:

    `"@types/ws" : "<8.5.5>",

假设问题在@types/ws v8.5.5中,因此在它修复之前,我们想要使用任何版本低于 8.5.5。

  1. 在编译之前,我需要运行一次以下命令:

    npm i --legacy-peer-deps

这个命令会更新package-lock.json。这个配置文件“冻结”了项目中所有Angular依赖项,以确保它们是当前可用的。

英文:

We had this issue in the build pipeline of a -fairly old- Angular project. Peculiarly, it failed every other build, since June 2023. I managed to resolve the issue as explained below. My solution is based on the remark of Salmin Skenderovic below the answer of Zen Donegan.

  1. In packages.json, I have added this dependency:

    "@types/ws" : "<8.5.5",

The assumption is that the bug is in @types/ws v8.5.5, so until it is fixed we want to use any version below 8.5.5.

  1. Before compiling, I needed to run this once:

    npm i --legacy-peer-deps

This command updates package-lock.json. This configuration file "freezes" all Angular dependencies for the project to a currently working set.

答案4

得分: 0

我删除了文件夹 node_modules/@types/ws,这对我有用。
下次我会使用 npm i --legacy-peer-deps 安装我的包。

英文:

I removed the folder node_modules/@types/ws and that worked for me.
Next time I'll install my package using npm i --legacy-peer-deps.

答案5

得分: 0

我遇到了类似的问题,但另外我还收到了以下消息:../node_modules/@types/node/globals.d.ts:72:13 - error TS2403: Subsequent variable declarations must have the same type. Variable &#39;AbortSignal&#39; must be of type &#39;{ new (): AbortSignal; prototype: AbortSignal; abort(reason?: any): AbortSignal; timeout(milliseconds: number): AbortSignal; }&#39;, but here has type &#39;{ new (): AbortSignal; prototype: AbortSignal; }&#39;.

所以,我所做的就是根据错误消息中的说明(顺便说一句,开发者已经添加了TODO注释),向global.d.ts文件的AbortSignal变量中添加了两行代码:

declare var AbortSignal: {
    prototype: AbortSignal;
    new(): AbortSignal;
    // TODO: Add abort() static
    abort(reason?: any): AbortSignal; // &lt;--------------lines which I added
    timeout(milliseconds: number): AbortSignal; //------|
};

之后,将其转换为JS就没有问题了 Type ‘Server’ is not generic.

英文:

I had similar problem, but additionally I got following message: ../node_modules/@types/node/globals.d.ts:72:13 - error TS2403: Subsequent variable declarations must have the same type. Variable &#39;AbortSignal&#39; must be of type &#39;{ new (): AbortSignal; prototype: AbortSignal; abort(reason?: any): AbortSignal; timeout(milliseconds: number): AbortSignal; }&#39;, but here has type &#39;{ new (): AbortSignal; prototype: AbortSignal; }&#39;.

So, what I did is simply added two lines of code to the global.d.ts to the AbortSignal variable, as it was stated in the error message (btw there was already TODO comment from developers):

declare var AbortSignal: {
    prototype: AbortSignal;
    new(): AbortSignal;
    // TODO: Add abort() static
    abort(reason?: any): AbortSignal; // &lt;--------------lines which I added
    timeout(milliseconds: number): AbortSignal; //------|
};

After that, converting to JS was without problems Type ‘Server’ is not generic.

答案6

得分: 0

当我遇到这个错误时,我发现它是由于我的@types/node包中的问题引起的。当我遇到错误时,我使用的是版本17。我尝试了其他每个主要版本,都没有错误。

所以我认为这实际上不是与ws模块有关的问题,正如其他人所建议的那样,而是与ws和某些版本的@types/node之间的问题。

英文:

When I encountered this error, I discovered that it was due to an issue in my @types/node package. I was on version 17 when I got the error. Every other major version I tried worked fine, no error.

So I don't think it is actually an issue with the ws module, as others have suggested, but rather an issue between ws and certain versions of @types/node.

答案7

得分: 0

我在我的package.json中有一个相当旧的@types/node版本,它与我的实际Node.js版本不匹配。

我使用以下命令删除了这个明确的依赖项:
npm uninstall @types/node(并让npm处理与实际对等依赖项的魔法)。

英文:

I had a pretty old version of @types/node defined in my package.json which did not match my actual version of Node.js.

i removed that explicit dependency with
npm uninstall @types/node (and let npm do the magic with an actual peer dependency).

huangapple
  • 本文由 发表于 2023年6月9日 06:43:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定