MioQuispe / create-ic-app

Use your favourite frontend framework with the Internet Computer
185 stars 42 forks source link

Import web3 error #10

Closed HelloRickey closed 3 years ago

HelloRickey commented 3 years ago

Use template-react, import Web3 from "web3" Prompt Object prototype may only be an Object or null: undefined

截屏2021-09-26 下午3 30 00
MioQuispe commented 3 years ago

Use template-react, import Web3 from "web3" Prompt Object prototype may only be an Object or null: undefined

截屏2021-09-26 下午3 30 00

Hey unfortunately web3js only provides a node based build (with require/Buffer assumptions etc.). Until they are done with their supposed refactoring to esm its not going to work out of the box with vite. I would suggest you either look at the various rollup-plugin-node-* packages and see if you can polyfill it in vite.config.js https://github.com/vitejs/vite/issues/847

Or ditch web3 for ethers.js which seems to be of higher quality (I understand if you cant though)

HelloRickey commented 3 years ago

Hey @MioQuispe , I used Ethers.js and it runs normally. It is even simpler than web3. Thank you very much for your create-ic-app, which makes it easier to build dfinity applications.