TypeError: (0 , wagmi_providers_public__WEBPACK_IMPORTED_MODULE_2__.publicProvider) is not a function #3226
-
I am trying to write an example project by following the codes in Wagmi official site: https://wagmi.sh/examples/connect-wallet. `layout.js : import Providers from './providers' const inter = Inter({ subsets: ['latin'] }) export const metadata = { export default function RootLayout({ children }) { `Providers.js : import { WagmiConfig, createConfig, configureChains, mainnet } from 'wagmi' import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet' // Configure chains & providers with the Alchemy provider. // Set up wagmi config // Pass config to React Context Provider
} But below error persists:
I really have no idea what happened. Can any guru kindly point out where the issue comes from? Thank you very much! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
you can try "use client" in first line,i have same problem with you and slove it。 "use client" |
Beta Was this translation helpful? Give feedback.
-
Awesome! Knowing this was as a result of 'use client' fixed my issue. I would also like to drop a hint. I ran into this error trying to use a provider at the html level. Note that you can't use "use client" at this level so what you can do it create a separate component and use it like it was used in this example // src/providers/WagmiProviderClient.tsx OR src/components/WagmiProviderClient.tsx
'use client';
import React from 'react';
import { RainbowKitProvider, connectorsForWallets, ConnectButton } from '@rainbow-me/rainbowkit';
import { injectedWallet, /* walletConnectWallet,*/ metaMaskWallet } from '@rainbow-me/rainbowkit/wallets';
import { WagmiConfig } from 'wagmi';
import { chains, wagmiConfig } from '@/lib/dapps/wagmiConfig';
const WagmiProviderClient: React.FC<{ children: React.ReactNode }> = ({ children }) => {
return (
<WagmiConfig config={wagmiConfig}>
<RainbowKitProvider chains={chains} initialChain={365}>
{children}
</RainbowKitProvider>
</WagmiConfig>
);
};
export default WagmiProviderClient; You layout will look like this // other code stuff
...
import WagmiProviderClient from "../providers/wagmiProviderClient";
const inter = Inter({ subsets: ["latin"] });
// mroe code stuff
...
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`${inter.className} bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 transition-colors duration-300`}>
<ThemeProvider>
<OauthProviders>
<WagmiProviderClient>
<div className="flex flex-col min-h-screen">
<NavbarTaiwind />
<main className="flex-grow">
<div className="container mx-auto flex justify-center items-start min-h-screen">
{children}
</div>
</main>
</div>
</WagmiProviderClient>
</OauthProviders>
</ThemeProvider>
</body>
</html >
);
} |
Beta Was this translation helpful? Give feedback.
you can try "use client" in first line,i have same problem with you and slove it。
"use client"
import { WagmiConfig, createConfig, configureChains, mainnet } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'