Building with v4 fails with "Module not found: Error: Can't resolve '@solana/web3.js'"

Describe the question

I ran the example application according to the following page.

https://web3auth.io/docs/guides/firebase

I was able to run yarn start without any problems
But when I run yarn build I get the following error

@solana/web3.js’ in ‘/home/snaka/projects/web3auth/examples/web-core-sdk/custom-authentication/ firebase-react-core-example/node_modules/@web3auth/solana-provider/dist’">
$ yarn build
yarn run v1.22.19
$ react-app-rewired build
Creating an optimized production build…
Failed to compile.

Module not found: Error: Can’t resolve ‘@solana/web3.js’ in ‘/home/snaka/projects/web3auth/examples/web-core-sdk/custom-authentication/ firebase-react-core-example/node_modules/@web3auth/solana-provider/dist’

I would like to know the correct way to handle this issue.

Steps to Reproduce

  1. clone repos : git clone https://github.com/Web3Auth/examples.git
  2. move directory: cd web-core-sdk/custom-authentication/firebase-react-core-example
  3. install dependencies: yarn
  4. build: yarn build
  5. The error mentioned above occurs.

Expected behavior:

Build succeeds.

Platform Details

  • Operating System: Windows (WSL2 - Ubuntu 20.04.4 LTS)
  • Platform used: Web
  • SDK used: Web
  • Browser Chrome
  • Web3Auth Version 4.0.0

Additional context

Actually, we are seeing the same issue in our product.
We have checked our product and the version of @web3auth/core and @web3auth/openlogin-adapter up to v3.3.0 is fine.
It seems that this problem occurs when the version is upgraded to v4.x.
I have stopped updating web3auth related packages because of this problem.

As the error message indicates, adding @solana/web3.js as a dependency of our product will solve the problem.
However, we do not use solana in our product.
Therefore, adding @solana/web3.js to our dependencies does not seem to be the right way to handle this.

I would like to know the correct way to handle this issue.



Originally posted by: snaka

Check the discussion at: https://github.com/orgs/Web3Auth/discussions/1212

OpenLogin Adapter is a multi-chain adapter which dynamically imports solana if the current chain namespace is selected as solana.
In v3 and below, we marked @solana/web3.js as a dependency and it was installed for everyone irrespective of whether they used solana.
In v4, we've marked the dependency as a peer dependency which means, dapps can choose whether to install the library or not.!
Because chainNamespace is a runtime variable, the js bundler builds the bundle with both ethereum and solana providers(separate chunks) but only loads the correct chunk at runtime.

So, it's safe to install @solana/web3.js to your dep list. Alternatively, you can no-op the module (resolve.alias: require.resolve('empty-module')



Originally posted by: chaitanyapotti