I have a NextJS (Typescript) setup with Express . I'm using Moralis, Wagmi and Web3Auth for authentication. The Metamask authentication works, but when I try to setup Web3 Authentication by importing Web3AuthConnector it throws me an error.
My code is like here in the documentation but looks to be an error about CommonJS and ESM which I can't handle. This is the error:
error - Error [ERR_REQUIRE_ESM]: require() of ES Module C:...\node_modules@web3auth\web3auth-wagmi-connector\node_modules@wagmi\core\dist\index.js from C:...\node_modules@web3auth\web3auth-wagmi-connector\dist\web3authWagmiConnector.cjs.js not supported. Instead change the require of index.js in C:...\node_modules@web3auth\web3auth-wagmi-connector\dist\web3authWagmiConnector.cjs.js to a dynamic import() which is available in all CommonJS modules.
I tried to set in package.json "type:module"
, and in tsconfig: module:"ES6"
or "ESNext"
but got the same error.
I got the same problem than you and I resolved it by create my own Connector. I didn't found any other way to do it.
I got the code from https://forum.moralis.io/t/solved-web3auth-wagmi-connector-doesnt-show-web3-wallets-as-a-login-option/20110/4.
Let me know if it's working for you ?
( You should add all the missing packages with yarn add )