umi: createUmi causes error in browser

I am using SvelteKit. Just a basic SvelteKit template is good enough for reproducing this issue. If the line of import below appears in the +page.svelte file, it will cause error.

import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';

The error

TypeError: import_os.homedir is not a function

It can be traced back to SolanaCliConfig from @soceanfi/solana-cli-config imported by umi-addsa-web3js. I don’t understand why SolanaCliConfig is needed for a client side library or why it is being included in the client side code.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

@beeman Here is the code I’m trying to get working: git@github.com:aek676/metaplex-nextjs.git

Image

Thanks for sharing! I got it working by making these changes to next.config.mjs:

/** @type {import('next').NextConfig} */
const nextConfig = {
    webpack: (config) => {
        config.resolve.fallback = {
            ...config.resolve.fallback,
            fs: false,
            child_process: false,
            readline: false,
            'stream/promises': false,
        }
        return config
    },
};

export default nextConfig;

Image

It has worked, Thanks

@beeman @aek676 looks like the umi package patch didn’t get released yet that I can see. Hold tight and I’ll get that pushed out to npm.

I’m having a look into this over the weekend for you all 😃

@beeman thank you so much!! this works totally fine, even with other Solana packages. I see in the last time the Sveltekit config doesn’t need to be so complicated like years ago to work with web3. 😃

@everythingspirals here is my temporary solution:

  • Copy & paste createWeb3JsEddsa to my own code and stub out the 2 functions: createKeypairFromFile, createKeypairFromSolanaConfig.
  • Copy & paste createUmi to my own code and use my custom createWeb3JsEddsa above.

The library should have just accept Uint8Array keypair and leave the loading key from file to the library user.