ERR_REQUIRE_ESM on @web3auth/web3auth-wagmi-connector/

I am having this error on next js and @web3auth/web3auth-wagmi-connector/

Server Error

Error: require() of ES Module /Users/alexandrecarvalheira/Documents/Buidl/BuidlProject/node_modules/@wagmi/core/dist/index.js from /Users/alexandrecarvalheira/Documents/Buidl/BuidlProject/node_modules/@web3auth/web3auth-wagmi-connector/dist/web3authWagmiConnector.cjs.js not supported. Instead change the require of index.js in /Users/alexandrecarvalheira/Documents/Buidl/BuidlProject/node_modules/@web3auth/web3auth-wagmi-connector/dist/web3authWagmiConnector.cjs.js to a dynamic import() which is available in all CommonJS modules.

This error happened while generating the page. Any console logs will be displayed in the terminal window.

This error is occurring because the @wagmi/core module is using an ES module syntax (export and import statements), which is not supported by Node.js when importing into a CommonJS module.

To fix this error, you need to change the way index.js is imported in the web3authWagmiConnector.cjs.js file to use a dynamic import() statement, which is supported by all CommonJS modules.

Try replace the current require() statement with the following code like this:

import('@wagmi/core').then(wagmiCore => {
  // use wagmiCore here