@solana web3 Failed to compile

Hi,

Recently, the frontend code started to give out the following error:

Failed to compile.
./node_modules/@solana/buffer-layout-utils/lib/esm/web3.mjs
Can’t import the named export ‘PublicKey’ from non EcmaScript module (only default export is available)

I’m using:
“moralis”: “^1.5.11”,
“react”: “^18.1.0”,

Thank you,

Before it worked fine and only now started to get error? Anything changed before starting to get that error?

Please take a look at the github issue below.

Looks like I’m not the only one experiencing this issue. The issue description is exactly the same as mine. The root cause might not be Moralis, but Moralis is using this library and giving out errors. Might still be worthwhile for you guys to follow through this. I can totally see more people are going to report this to you guys in the next few days. Thanks

Can you try using the latest Moralis SDK version 1.7.0. Are you using any other dependencies or doing anything else in your project, react-moralis, etc.? To see how this can be replicated.

Yes, I’m also using react-moralis 1.3.5. The problem still persists after upgrading Moralis SDK to 1.7.0.

I tried to replicate the issue with a minimal setup. But interestingly, even the tutorial on your website (https://docs.moralis.io/moralis-dapp/connect-the-sdk/connect-with-react) is now broken after step3 (after I put in the MoralisProvider).

Installation steps as follows:
yarn create react-app my-app --template typescript
cd my-app
yarn add moralis react-moralis
yarn add magic-sdk @walletconnect/web3-provider @web3auth/web3auth

Appreciate your help!

Thanks. I am able to replicate this error on my end. I get the usual webpack 5 issues with polyfills after adding the MoralisProvider and then I switched to 4.0.3 to get rid of them, now I get that Solana error.

This was the fix for that on v4. There is a link at the bottom of that post for v5.

Thank you. It works. Now it’s giving me two warnings. How do you suppress them?

Compiled with warnings.
./node_modules/magic-sdk/dist/es/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

./node_modules/magic-sdk/dist/es/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

This issue is addressed here. Critical dependency: require function is used in a way in which dependencies cannot be statically extracted · Issue #295 · magiclabs/magic-js (github.com)

Everything should work otherwise.

Thank you. Now nothing is complaining. I really miss the good old days (only a few months ago) when setting up a moralis project in react only took two commands. Do you guys have plans to revisit react-moralis?

react-moralis is still being worked on. The original issue seems unrelated to Moralis specifically.

Hi,

I am having this same issue ./node_modules/@solana/buffer-layout-utils/lib/esm/web3.mjs Can't import the named export 'PublicKey' from non EcmaScript module (only default export is available)

Tried solution for v4 in this link, but in my windows machine am having error in this line sed: can't read s/react-scripts /react-app-rewired /g: No such file or directory

Any suggestions on how can I overcome this solana error?

Tried solution for v4 in this link, but in my windows machine am having error in this line sed: can't read s/react-scripts /react-app-rewired /g: No such file or directory

This is for Linux. Go into your package.json and under scripts change all react-scripts to react-app-rewired.