metaplex-foundation / js

A JavaScript SDK for interacting with Metaplex's programs
357 stars 182 forks source link

'TypeError: Invalid URL' when making Metaplex object #129

Closed theInfiniteWill closed 2 years ago

theInfiniteWill commented 2 years ago

I'll always get TypeError: Invalid URL when I create the Metaplex object even when using a known good Connection.

Example code in Node. Running Node 18.2 locally this.connection = new Connection(clusterApiUrl('devnet')); this.metaplex = Metaplex.make(this.connection)

I'll get the error when I'm trying to create the metaplex object. TypeError: Invalid URL. I can confirm that the connection itself works fine as I'm able to make and receive calls with it.

A more specific call stack using tsc since I saw another bug that mentioned usingtsc fixed it for them

TypeError: Invalid URL
    at new NodeError (node:internal/errors:377:5)
    at URL.onParseError (node:internal/url:563:9)
    at new URL (node:internal/url:643:5)
    at resolveClusterFromEndpoint (node_modules/@metaplex-foundation/js-next/src/types/Cluster.ts:28:18)
    at Object.resolveClusterFromConnection (node_modules/@metaplex-foundation/js-next/src/types/Cluster.ts:24:10)
    at new Metaplex (node_modules/@metaplex-foundation/js-next/src/Metaplex.ts:18:39)
    at Function.make (/node_modules/@metaplex-foundation/js-next/src/Metaplex.ts:23:12)

What am I doing wrong here?

lorisleiva commented 2 years ago

Are you using the latest version of @solana/web3.js?

The resolveClusterFromConnection method relies on the existence of connection.rpcEndpoint which was added to the Connection class fairly recently.

theInfiniteWill commented 2 years ago

Updating to v1.43.6 did fix it. Thanks for the help