widget icon indicating copy to clipboard operation
widget copied to clipboard

Compilation error with wagmi v2 in Next.js

Open heyitsarpit opened this issue 1 year ago • 7 comments

Error Stack Trace

index.js:627 Uncaught Error: Module not found: ESM packages (@wagmi/connectors) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]_encodin_uqzfhbc6fcmqavn6anlzgdie3i/node_modules/@lifi/wallet-management/cjs/wallets.js
./node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]_encodin_uqzfhbc6fcmqavn6anlzgdie3i/node_modules/@lifi/wallet-management/cjs/index.js
./node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]_i_p7e23oxgfqgw2hcjfvhcq6d4su/node_modules/@lifi/widget/cjs/providers/WalletProvider/WalletProvider.js
./node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]_i_p7e23oxgfqgw2hcjfvhcq6d4su/node_modules/@lifi/widget/cjs/providers/WalletProvider/index.js
./node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]_i_p7e23oxgfqgw2hcjfvhcq6d4su/node_modules/@lifi/widget/cjs/index.js
./ui/Bridge/Lifi/Widget.tsx
./ui/Bridge/Lifi/index.tsx
./ui/Header.tsx
./pages/_app.tsx

Versions

viem - 2.9.21
wagmi - 2.5.20
@lifi/sdk - 2.5.1
@lifi/widget - 2.10.2
next - 14.2.2
typescript - 5.2.2
pnpm - 9.0.6

heyitsarpit avatar May 02 '24 10:05 heyitsarpit

@heyitsarpit Hey, widget v2 doesn't support wagmi v2. Please use widget v3.

chybisov avatar May 07 '24 09:05 chybisov

@heyitsarpit Hey, widget v2 doesn't support wagmi v2. Please use widget v3.

I see that widget and sdk v3 are in alpha on npm. I suppose it's not safe to integrate them right now?

heyitsarpit avatar May 07 '24 10:05 heyitsarpit

@heyitsarpit It is pretty stable, and there shouldn't be any major breaking changes down the line. We will release a beta soon while we prepare documentation for the major release.

chybisov avatar May 07 '24 10:05 chybisov

okay thanks I'll look into this.

heyitsarpit avatar May 07 '24 10:05 heyitsarpit

@chybisov in the new config(v3), what replaces the walletManagement and containerStyle options? this is what we are doing currently. and it works with wagmi v2.

      walletManagement: {
        signer: signer,
        connect: async () => {
          const connector = connectors[0]

          await connectAsync({ connector })
          const provider = (await connector.getProvider()) as Web3Provider

          return provider?.getSigner() as Signer
        },
        disconnect: async () => {
          await disconnect()
        },
        switchChain: async (chainId) => {
          await switchChainAsync({
            chainId: chainId as SUPPORTED_CHAINS_IDS
          })
          const client = wagmiConfig.getClient({
            chainId: chainId as SUPPORTED_CHAINS_IDS
          })

          return walletClientToSigner(client)
        }
      }

heyitsarpit avatar May 07 '24 11:05 heyitsarpit

@heyitsarpit Please take a look at the Rainbowkit example https://github.com/lifinance/widget/tree/main/examples/rainbowkit

TL;DR You don't have to use walletManagement prop anymore and everything should work out of the box if your app and the widget are wrapped in WagmiProvider. Also, please make sure you configure all the chains in the wagmi config you would like to use with the widget.

chybisov avatar May 07 '24 11:05 chybisov

awesome let me test this out

heyitsarpit avatar May 07 '24 11:05 heyitsarpit

@heyitsarpit the containerStyle prop seems to have moved under theme.container prop now

haroon-schmrkow avatar May 29 '24 13:05 haroon-schmrkow

The Widget v3 has been released. Please see the documentation here https://docs.li.fi/integrate-li.fi-widget/li.fi-widget-overview

chybisov avatar Jun 27 '24 14:06 chybisov