Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After updating: Could not find a declaration file for module 'ws' #5202

Closed
aayla-secura opened this issue Sep 28, 2024 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@aayla-secura
Copy link

Describe the bug

Probably related to #5201 but solution in there did not work in this case.

I just updated from socket.io-client v4.7.5 to v4.8.0 and I am now getting the following error during typescript compilation:

node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts:12:108 - error TS7016: Could not find a declaration file for module 'ws'. '.../node_modules/engine.io-client/node_modules/ws/wrapper.mjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`

12     createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): import("ws");
                                                                                                              ~~~~

Installing @types/ws results in a different error:

node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts:12:101 - error TS1340: Module 'ws' does not refer to a type, but is used as a type here. Did you mean 'typeof import('ws')'?

12     createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): import("ws");

Reverting back to 4.7.5 works fine again.


My project is TypeScript with target: es2022 and module: preserve options. I'm doing

import { io } from "socket.io-client";

Expected behavior
Type declarations should be included and compilation should not error.

Platform:

  • OS: Ubuntu on Window Subsystem for Linux; Windows 11
@aayla-secura aayla-secura added the to triage Waiting to be triaged by a member of the team label Sep 28, 2024
CraigMacomber added a commit to microsoft/FluidFramework that referenced this issue Oct 2, 2024
## Description

Update client dependencies, holding back socket.io-client to avoid
socketio/socket.io#5202.

Makes type tests target ~ version, to avoid duplicating previous package
versions:
`pnpm exec flub typetests -g client --exact "~2.3.0"`
sonalideshpandemsft pushed a commit to microsoft/FluidFramework that referenced this issue Oct 7, 2024
## Description

Update client dependencies, holding back socket.io-client to avoid
socketio/socket.io#5202.

Makes type tests target ~ version, to avoid duplicating previous package
versions:
`pnpm exec flub typetests -g client --exact "~2.3.0"`
@Nosfistis
Copy link

node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts:12:101 - error TS1340: Module 'ws' does not refer to a type, but is used as a type here. Did you mean 'typeof import('ws')'?

12     createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): import("ws");

This also happened to me when importing socket.io-client in an Angular app, when using "moduleResolution": "bundler". There is no issue in version 4.7.5.

darrachequesne added a commit that referenced this issue Oct 19, 2024
Before this change, the following error would be thrown when compiling
with TypeScript:

```
node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts:12:101 - error TS1340: Module 'ws' does not refer to a type, but is used as a type here. Did you mean 'typeof import('ws')'?

12     createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): import("ws");
                                                                                                       ~~~~~~~~~~~~
```

This behavior was introduced in [1], included in version `6.6.0`.

The return type is forced as `any`, so that the `@types/ws` dependency
is optional.

[1]: f4d898e

Related: #5202
@darrachequesne darrachequesne added bug Something isn't working and removed to triage Waiting to be triaged by a member of the team labels Oct 19, 2024
@darrachequesne
Copy link
Member

This should be fixed by 175a2c5, included in engine.io-client@6.6.2. Could you please check?

@aayla-secura
Copy link
Author

Thank you , indeed I no longer see the error after doing those updates.

@Nosfistis
Copy link

This is not yet fixed in socket.io-client@4.8.1 which was published yesterday, as the target engine.io-client version was not updated.

Using package.json overrides to set the version explicitly to 6.6.2 works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants