4

I was trying to work with the @solana/spl-token package in my xNFT with the latest xNFT-starter repository.

When I use any function I get the following error:

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

As far as I was able to figure out, that means that mjs files not being compiled by the Metro Bundler.

I tried multiple way adding the extension in the metro.config.js file but couldn't get it to work.

Highly looking forward to any hints how to solve this. A couple other people had that issue as well

1
  • Can you share some code snippets? Possibly the import statement?
    – Joe C
    Commented Oct 11, 2023 at 16:11

1 Answer 1

1

Looking at your error i think its more to do with the pubkeys than with the token package. I havent used spl-token in my xNFT but solana web3 works fine. WIll do some testing with token in the next week and circle back.

Make sure you are including the pubkey type, like so: import { Connection, Keypair, SystemProgram, LAMPORTS_PER_SOL, Transaction, TransactionInstruction, sendAndConfirmTransaction, PublicKey, } from '@solana/web3.js';

also make sure to run yarn install, update to the most recent version of the xNFT starter version and cli, and install the spl-token before building.

If you share code, will be able to help with a bit more precision.

1
  • Capitalization and spelling errors
    – Ahri
    Commented Dec 28, 2023 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.