最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - @solanaweb3.js Cannot find module 'rpc-websocketsdistlibclient' - Stack Overflow

programmeradmin6浏览0评论

In my node.js project I have "@raydium-io/raydium-sdk": "^1.3.1-beta.52" dependency, and it has this deps:

`-- @project-serum/[email protected]
  `-- @solana/[email protected]
    `-- [email protected]

When I try to do import { Connection } from '@solana/web3.js' and run the thing I get this error:

[INFO] 20:49:10 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.2, typescript ver. 5.4.5)
Error: Cannot find module 'rpc-websockets/dist/lib/client'

I dont understand whats the problem, probably something with module resolution, but I am not sure. I also checked and rpc-websockets are in the node_modules.

Any idea how to fix this?

In my node.js project I have "@raydium-io/raydium-sdk": "^1.3.1-beta.52" dependency, and it has this deps:

`-- @project-serum/[email protected]
  `-- @solana/[email protected]
    `-- [email protected]

When I try to do import { Connection } from '@solana/web3.js' and run the thing I get this error:

[INFO] 20:49:10 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.2, typescript ver. 5.4.5)
Error: Cannot find module 'rpc-websockets/dist/lib/client'

I dont understand whats the problem, probably something with module resolution, but I am not sure. I also checked and rpc-websockets are in the node_modules.

Any idea how to fix this?

Share Improve this question asked Jun 2, 2024 at 14:01 salat _salat _ 3415 silver badges13 bronze badges
Add a ment  | 

9 Answers 9

Reset to default 7

Solved by explicitly stating "rpc-websockets": "7.11.0" in dependencies. It seems like latest version 7.11.0 is not patible.

Issue is related to last release of rpc-websockets

I fixed this with adding

"resolutions": {
   "rpc-websockets": "7.11.0"
}

to package.json

Just +1 as I'm having the same problem. Quick way to reproduce is creating a new NPM project (npm init), set "type": "module" in package.json and run npm i @solana/web3.js.

Trying to run any file (index.js) that just imports web3.js results in that error

import {} from "@solana/web3.js";
console.log("Hello world");
node:internal/modules/cjs/loader:1144
  const err = new Error(message);
              ^

Error: Cannot find module 'rpc-websockets/dist/lib/client'

I downgraded to "rpc-websockets": "7.10.0" which works for me.

Make sure to explicitly state this in package.json

I had the same issue today and I fixed it by importing the rpc-websockets/dist/lib/client by itself before importing the solana/web3.js:

import 'rpc-websockets/dist/lib/client';

import {
  Connection,
  Keypair,
  clusterApiUrl,
} from '@solana/web3.js';

This fixed the issue for me, because the rpc-websockets module was always there but the error was still showing even after downgrading the rpc-websockets or trying older versions of solana.web3.js.

Downgrading to [email protected] using yarn add solved this for me

Ok so what I did is to check for websocket version that I have using:

npm list rpc-websockets

and I have: [email protected]

so what I did is to downgrade to 7.11.0 using

npm install rpc-websockets@^7.11.0

If you are seeing an error like Module not found: Can't resolve 'rpc-websockets/dist/lib/client.cjs' when trying to use the SDK, you can fix this by adding the following to your package.json file:

For npm:

"overrides": {
  "rpc-websockets": "7.10.0",
  "@solana/web3.js": "1.91.6"
},

For yarn:

"resolutions": {
  "rpc-websockets": "7.10.0",
  "@solana/web3.js": "1.91.6"
} 

Notes: Note that even if you are not using Solana, you still need to include the @solana/web3 line below. This will be fixed in the next major SDK release (V3).

Source: https://docs.dynamic.xyz/troubleshooting/react/cannot-resolve-rpc-websockets

fixed by executing

npm install [email protected]

发布评论

评论列表(0)

  1. 暂无评论