ourzora / zora-protocol

Monorepo for Zora Protocol (contracts & sdks)
MIT License
133 stars 85 forks source link

'Dynamic require of "punycode" is not supported' when I import zora protocol sdk #412

Closed boosik-riverbank closed 5 months ago

boosik-riverbank commented 6 months ago

Hi, I am boosik developing with zora protocol sdk + nextjs for minting my NFT in frontend. I got these error when I import zora protocol-sdk. I am trying zora protocol-sdk + Viem, below is my code-base.

import {createMintClient} from "@zoralabs/protocol-sdk";
...
const mintClient = createMintClient({ chain: walletClient.chain! })

And I got this error in browser,

Uncaught Error: Dynamic require of "punycode" is not supported
    at eval (index.js:105:9)
    at ../../node_modules/whatwg-url/lib/url-state-machine.js (index.js:486:20)
    at __require2 (index.js:111:50)
    at ../../node_modules/whatwg-url/lib/URL-impl.js (index.js:1558:15)
    at __require2 (index.js:111:50)
    at ../../node_modules/whatwg-url/lib/URL.js (index.js:1717:16)
    at __require2 (index.js:111:50)
    at ../../node_modules/whatwg-url/lib/public-api.js (index.js:1898:19)
    at __require2 (index.js:111:50)

Is there any tip for handling this error?

iainnash commented 5 months ago

Hello!

Are you using this with wagmi/viem?

Was this app pre-existing before this change?

I don't think we utilize punycode/whatwg-url for our own purposes but a dependent package will. Do you use something like vite or webpack etc to setup the website? This seems to be a loader error. Are you using type="module" with raw imports?

What would help is a package-lock.json or yarn.lock or more context as how you're running the page. Would also be helpful to know what index.js is.

intergalacticspacehighway commented 5 months ago

@iainnash seems same issue here. the punnycode import gets added in dist folder of protocol-sdk. node_modules/@zoralabs/protocol-sdk/dist/index.js:395:9. Looks like maybe an issue with bundling setup?

Screenshot 2024-05-16 at 12 32 13 PM
intergalacticspacehighway commented 5 months ago

Some findings. var CrossFetch = __toESM(require_node_ponyfill(), 1); is getting injected in the dist/index.js of @zoralabs/protocol-sdk's distribution bundle, probably due to graphql-request, this requires the punycode. Ideally this should not be a part of protocol-sdk's bundle, but i suspect some build script issues. The issue gets fixed if you comment the above line out.

iainnash commented 5 months ago

Hi,

This has been fixed, graphql-request has been removed as a dep.

Feel free to re-open if this arises again.