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

TypeError on Creating HypercertClient: MeshCache is not a constructor #1189

Closed
yangnoahlin opened this issue Nov 23, 2023 · 8 comments
Closed

Comments

@yangnoahlin
Copy link

Which area(s) of Hypercerts are affected? (leave empty if unsure)

SDK

To Reproduce

  1. Set up the configuration parameters for HypercertClient.
  2. Run the following code snippet:
const client = new HypercertClient({
  // configuration parameters
});
  1. Observe the error "TypeError: MeshCache is not a constructor" appears.

Describe the Bug

I encounter a TypeError when attempting to create a HypercertClient instance. The error message is "TypeError: MeshCache is not a constructor". This error occurs when I run my application using the @hypercerts-org/sdk package.

Expected Behavior

I expect the HypercertClient to be successfully instantiated with the provided configuration parameters, without throwing a type error. Normally, this should initialize the client and prepare it for interactions with the Hypercerts services.

@yangnoahlin
Copy link
Author

"dependencies": {
    "@hypercerts-org/sdk": "^1.0.0-alpha.9"
  }

@bitbeckers
Copy link
Contributor

Are you using NextJS? Could you try addings this line to the next.config?

transpilePackages: ["@hypercerts-org/sdk"],

Here's a reference: https://github.com/hypercerts-org/hypercerts/blob/main/frontend/next.config.mjs

If that doesn't help, can you share a reproducable example or the repo you're using?

@yangnoahlin
Copy link
Author

I am directly executing the script using Node by running node hypercerts_test.js. Below is my hypercerts_test.js content.

const { HypercertClient } = require("@hypercerts-org/sdk");
const { ethers } = require("ethers");
const { http } = require("viem");

const transport = http("https://optimism-mainnet.infura.io/v3/xxxxx");

const client = new HypercertClient({
  chain: {id:10}, // optimism  
  nftStorageToken: "<API KEY from https://nft.storage/manage/>",
  web3StorageToken: "<did:key from https://console.web3.storage/>",
  walletClient: {
    transport: transport,
    chain: "optimism",
    account: "0x...",
  },
  easContractAddress: "0x...",
});

@bitbeckers
Copy link
Contributor

Ok, so you're running it directly. The error bubbles up from the graphClient dependency we use, and we never ran this client as a server component since the focus has been support developing apps. I'll try and get a fix for this over the weekend, apologies for the inconvenience.

@yangnoahlin
Copy link
Author

Thanks a lot for the quick response and for looking into this! Really appreciate the effort to get a fix by the weekend. If there's anything I can do to help, just let me know. Cheers!

@bitbeckers
Copy link
Contributor

I've been able to reproduce locally, now to find the fix...

@bitbeckers
Copy link
Contributor

Alrigth @yangnoahlin it led to a small rabbithole but the bug has been squashed. Can you try running with SDK version 1.0.0-alpha.13

FYI, the issue turned out to be an async call in the Graph client constructor that wasn't marked as async, which doesn't break for ESM modules because they are inherently async, but in CJS it breaks the initialisation of the Indexer Class.

For reference you can find a couple of barebone implementations using the latest SDK here: https://github.com/hypercerts-org/demo-apps

Can you let me know if if work on your machine as well? If not, please share any errors/log/whatever.

@yangnoahlin
Copy link
Author

👏 Huge thanks to bitbeckers!

Successfully minted my Hypercerts with 1.0.0-alpha.13. 🚀
Really appreciate your quick fix over the weekend! You're a star! 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants