web3.js
web3.js copied to clipboard
Web3 Expo support
Web3.js`s version comes '4.x' now; We can still only import the web3 browser version in our Vite and TS project;
the 'vite:import-analysis' plugin will throw an error, telling me the 'web3 'package is not exporting web3.min.js;
so i have a idea; as we add a declaration in web3 package.json ; and next, everything are working fine; codes are as follow:
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.js",
"require": "./lib/commonjs/index.js"
},
// Add this line. it can solve errors from vite-scan;!!!
"./dist/web3.min.js": "./dist/web3.min.js"
},
how i use web3.js 4.x in my vite&ts project;
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
web3: "web3/dist/web3.min.js",
},
}
Environment
- Web3.js 4.0.1
- vite & ts & vue3;
- windows 10;
Thanks @yao8384 for opening an issue for this. We will look into it.
Hi, I think it also affects web3-validator package. When trying to use web3-validator in Expo the package is resolved as undefined. After adding this line to it's package.json it works ok.
We should test 4.x builds with Expo.
I use this patch for the latest web3 4.4.0 & bare expo 49.0 & RN 0.72.9: