wallet-adapter icon indicating copy to clipboard operation
wallet-adapter copied to clipboard

Can't import the named export 'Connection' from non EcmaScript module (only default export is available)

Open springrainroni opened this issue 2 years ago • 8 comments

import React, { FC, useMemo } from 'react'; import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react'; import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'; import { GlowWalletAdapter, PhantomWalletAdapter, SlopeWalletAdapter, SolflareWalletAdapter, SolletExtensionWalletAdapter, SolletWalletAdapter, TorusWalletAdapter, } from '@solana/wallet-adapter-wallets'; import { WalletModalProvider, WalletDisconnectButton, WalletMultiButton } from '@solana/wallet-adapter-react-ui'; import { clusterApiUrl } from '@solana/web3.js';

// Default styles that can be overridden by your app require('@solana/wallet-adapter-react-ui/styles.css'); const PhanthomLogin = props => { // const Wallet: FC = () => { // The network can be set to 'devnet', 'testnet', or 'mainnet-beta'. const network = WalletAdapterNetwork.Devnet;

// You can also provide a custom RPC endpoint.
const endpoint = useMemo(() => clusterApiUrl(network), [network]);

// @solana/wallet-adapter-wallets includes all the adapters but supports tree shaking and lazy loading --
// Only the wallets you configure here will be compiled into your application, and only the dependencies
// of wallets that your users connect to will be loaded.
const wallets = useMemo(
    () => [
        new PhantomWalletAdapter(),
        new GlowWalletAdapter(),
        new SlopeWalletAdapter(),
        new SolflareWalletAdapter({ network }),
        new TorusWalletAdapter(),
    ],
    [network]
);

return (
    <ConnectionProvider endpoint={endpoint}>
        <WalletProvider wallets={wallets} autoConnect>
            <WalletModalProvider>
                <WalletMultiButton />
                <WalletDisconnectButton />
                { /* Your app's components go here, nested within the context providers. */ }
            </WalletModalProvider>
        </WalletProvider>
    </ConnectionProvider>
);

}; export default PhanthomLogin; it shows me error Can't import the named export 'Connection' from non EcmaScript module (only default export is available)

springrainroni avatar May 10 '22 11:05 springrainroni

I'm having the exact same issue as of now

ghost avatar May 10 '22 15:05 ghost

I am also have same issue

krobinsmith avatar May 11 '22 02:05 krobinsmith

I was able to fix this error with the following piece in craco config

webpack: {
    configure: {
      module: {
        rules: [
          {
            type: 'javascript/auto',
            test: /\.mjs$/,
            use: [],
          },
        ],
      },
    },
  },

However, then I get the error

You have tried to  read "publicKey" on a WalletContext without providing one. Make sure to render a WalletProvider as an ancestor of the component that uses WalletContext

yuloskov avatar May 11 '22 13:05 yuloskov

Btw, I'm using React 17. However in the docs it requires Reac 18, I think. I was able to make the library work with React 18.

yuloskov avatar May 11 '22 13:05 yuloskov

@yuloskov can you share your package.json? I'm encountering the same error. I tried to upgrade to react 18 but not working

    "react": "18.1.0",
    "react-dom": "18.1.0",

andychoww avatar Jun 15 '22 03:06 andychoww

I was able to fix this error with the following piece in craco config

webpack: {
    configure: {
      module: {
        rules: [
          {
            type: 'javascript/auto',
            test: /\.mjs$/,
            use: [],
          },
        ],
      },
    },
  },

However, then I get the error

You have tried to  read "publicKey" on a WalletContext without providing one. Make sure to render a WalletProvider as an ancestor of the component that uses WalletContext

You error is with Context, you need add Provider Context to app.js for use it

Joan1590 avatar Jun 16 '22 23:06 Joan1590

Found a way to fix this following this answer issue#265

markgalang avatar Jun 22 '22 13:06 markgalang

Closing since this issue can be avoided using any of the React starter projects

https://github.com/solana-labs/wallet-adapter#starter-projects

jordaaash avatar Aug 17 '22 00:08 jordaaash