Can't import as esm module in vite project.
See original GitHub issueDescribe the bug
@ethersproject/bignumber
package is using bn.js
as a dependency. While bn.js
is coding with umd
way.
So in vite
project it throw error like this:
Uncaught SyntaxError: The requested module '/node_modules/bn.js/lib/bn.js' does not provide an export named 'default'
Reproduction steps
- Create a new
vite
project then add@walletconnect/ethereum-provider@2.0.0-beta.14
andethers@5.4.1
deps. - Coding
import WalletConnectProvider from '@walletconnect/ethereum-provider'
in vue file.
The error occur. I don’t think this error is caused by @walletconnect/ethereum-provider
package as it doesn’t depend on it and it’s really not correct to import umd
module in vite
way.
Environment: MacOS 11.1 yarn 1.22.10 node v14.17.1 npm 7.19.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Features | Vite
Vite will detect such bare module imports in all served source files and perform the following: Pre-bundle them to improve page loading speed...
Read more >JavaScript modules - MDN Web Docs
Use of native JavaScript modules is dependent on the import and export ... They need to be top-level items; you can't use export...
Read more >Yarn 3.1, Vite 2.9, cannot find package vite - Stack Overflow
at new NodeError (node:internal/errors:377:5) at packageResolve (node:internal/modules/esm/resolve:910:9) ... // vite.config.js excerpt import { ...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
You can't require() ESM scripts; you can only import ESM scripts, like this: import {foo} from 'foo'; CJS scripts can't use static import...
Read more >How to Install and Use Vite in Your Web Projects
Vite will pre-bundle the source files to speed up page loading and convert CommonJS / UMD modules to ESM. To allow browsers to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 Same issue with nuxt 3 and ethersjs 5.5.2. Any updates?
Here a working nuxt config with right vite settings