Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

fix: import EthereumProvider instead of default #382

Merged
merged 2 commits into from
Jul 3, 2023

Conversation

oxSaturn
Copy link
Contributor

@oxSaturn oxSaturn commented Jun 29, 2023

Description

I ran into this Uncaught (in promise) TypeError: EthereumProvider.init is not a function at WalletConnectConnector.initProvider_fn error when testing my React components with vitest, and I can saw multiple similar reports:

  1. bug: TypeError: EthereumProvider.init #370
  2. bug: EthereumProvider.init is not a function #379

The problem I found is how we use dynamic import in ESM like below https://github.com/wagmi-dev/references/blob/eeed52e2d0170324c53c145e54dc089761a414cb/packages/connectors/src/walletConnect.ts#L280-L284

Unfortunately, init is missing from EthereumProvider in this case.

I've set up a small example here where you can check the test.cjs file https://stackblitz.com/edit/stackblitz-starters-4alfhc?file=index.mjs, no bundlers like esbuild or webpack messing around, so it seems it's how the import works, though I haven't yet found the standard to reference.

Additional Information

Your ENS/address:

@changeset-bot
Copy link

changeset-bot bot commented Jun 29, 2023

🦋 Changeset detected

Latest commit: 04b393a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@wagmi/connectors Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@oxSaturn
Copy link
Contributor Author

@oxSaturn
Copy link
Contributor Author

oxSaturn commented Jun 29, 2023

All right, I can confirm it's a misuse in the code, when we import {default} from a CommonJS module, it actually imports the exports object, not exports.default. {default} is not a destructuring here.

see https://stackoverflow.com/a/76580524/22148155 for more.

@jxom jxom merged commit ff53857 into wevm:main Jul 3, 2023
5 of 6 checks passed
@oxSaturn oxSaturn deleted the bugfix/fix-init-undefined branch July 3, 2023 02:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants