skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

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


  2. 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'
    
    Login or Signup to reply.
  3. I downgraded to "rpc-websockets": "7.10.0" which works for me.

    Make sure to explicitly state this in package.json

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search