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

Error: Could not find a declaration file for module 'ws' ... Try npm i --save-dev @types/ws... #6162

Closed
Muhammad-Altabba opened this issue Jun 7, 2023 · 2 comments · Fixed by #6226
Assignees
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@Muhammad-Altabba
Copy link
Contributor

Description

I faced the following errors when I used web3 as the only dependency inside the chainlink plugin:

node_modules/isomorphic-ws/index.d.ts:6:28 - error TS7016: Could not find a declaration file for module 'ws'. '/web3.js-plugin-chainlink/node_modules/ws/index.js' 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';`

6 import WebSocket = require('ws')
                             ~~~~

node_modules/web3-providers-ws/lib/commonjs/index.d.ts:4:21 - error TS2305: Module '"isomorphic-ws"' has no exported member 'ClientOptions'.

4 import WebSocket, { ClientOptions, CloseEvent } from 'isomorphic-ws';
                      ~~~~~~~~~~~~~

node_modules/web3-providers-ws/lib/commonjs/index.d.ts:4:36 - error TS2305: Module '"isomorphic-ws"' has no exported member 'CloseEvent'.

4 import WebSocket, { ClientOptions, CloseEvent } from 'isomorphic-ws';
                                     ~~~~~~~~~~

node_modules/web3-providers-ws/lib/commonjs/index.d.ts:4:54 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

4 import WebSocket, { ClientOptions, CloseEvent } from 'isomorphic-ws';
                                                       ~~~~~~~~~~~~~~~

node_modules/web3-providers-ws/lib/commonjs/index.d.ts:8:10 - error TS2305: Module '"isomorphic-ws"' has no exported member 'ClientOptions'.

8 export { ClientOptions } from 'isomorphic-ws';
           ~~~~~~~~~~~~~

node_modules/web3-providers-ws/lib/commonjs/index.d.ts:8:31 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

8 export { ClientOptions } from 'isomorphic-ws';
                                ~~~~~~~~~~~~~~~

node_modules/web3-providers-ws/lib/commonjs/index.d.ts:1:23 - error TS2688: Cannot find type definition file for 'ws'.

1 /// <reference types="ws" />
                        ~~

And I had overcome his by adding
@types/ws to the devDependencies as you can find in: https://github.com/ChainSafe/web3.js-plugin-chainlink/pull/27/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519

Steps to reproduce the behavior

Thoughts

We need to prevent this error from happening without the addition of @types/ws to the devDependencies to the project that uses web3.
And we need to prevent this for all devDependencies used inside our sub-packages. The error shows for ws. But it could happen with other packages depending on the scenario.

@Muhammad-Altabba
Copy link
Contributor Author

Whoever faces this issue, in the meantime he can run:
npm i --save-dev @types/ws or yarn add --dev @types/ws

And if the missed package was something other than the types of ws. Try, similarly, to install it on your devDependencies.

Muhammad-Altabba added a commit to Muhammad-Altabba/ChainTrust that referenced this issue Jun 11, 2023
Skipping the lib check till the following issues identified here are resolved:
 - web3/web3.js#6162
 - web3/web3.js#6185
@Muhammad-Altabba Muhammad-Altabba added the Good First Issue Great to learn the internals of web3.js label Jun 12, 2023
@Themvp07
Copy link

verified

@Muhammad-Altabba Muhammad-Altabba mentioned this issue Jun 14, 2023
17 tasks
@jdevcs jdevcs removed Discussion Good First Issue Great to learn the internals of web3.js labels Jun 14, 2023
@jdevcs jdevcs self-assigned this Jun 14, 2023
@jdevcs jdevcs mentioned this issue Jun 15, 2023
17 tasks
@mconnelly8 mconnelly8 added the Bug Addressing a bug label Jun 19, 2023
@jdevcs jdevcs closed this as completed Jun 20, 2023
@jdevcs jdevcs mentioned this issue Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants