-
Describe the bugI am running a vite.js app with web3 installed. I can confirm that the error comes from the contract method generated from my ABI: Reproductionhttps://github.com/nybroe/web3_vite_call_of_undefined/tree/main System InfoSystem:
OS: Windows 10 10.0.19044
CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
Memory: 35.34 GB / 63.73 GB
Binaries:
Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.50)
Internet Explorer: 11.0.19041.1566
npmPackages:
vite: ^2.7.2 => 2.9.6 Used Package Managernpm LogsUncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')
at tS.Q1 (index.4c6ddf14.js:49:31241)
at new jc (index.4c6ddf14.js:49:52725)
at new tS (index.4c6ddf14.js:49:55512)
at index.4c6ddf14.js:49:57789
at index.4c6ddf14.js:49:62640
at index.4c6ddf14.js:49:9995
at o (index.4c6ddf14.js:49:84548)
at Object.d (index.4c6ddf14.js:49:84731)
at Object.Hb [as sha3] (index.4c6ddf14.js:50:20120)
at Ft.KG [as outputFormatter] (index.4c6ddf14.js:51:2148) Validations
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 11 replies
-
Moving to a discussion, the reproduction requires installing metamask and there are a lot of dependencies like buffer used. If you can create a minimal reproduction of a Vite issue, please create another bug report. If not, this looks like a setup issue as you are using dependencies that are using node builtins. You can also join https://chat.vitejs.dev or check the issues in the repo. Looks like other users are dealing with web3 issues. Ideally, web3 will offer a package that properly works in the browser. |
Beta Was this translation helpful? Give feedback.
-
Using the pre-bundled // vite.config.js
import { defineConfig } from 'vite'
export default defineConfig({
⋮
resolve: {
alias: {
web3: 'web3/dist/web3.min.js',
},
// or
alias: [
{
find: 'web3',
replacement: 'web3/dist/web3.min.js',
},
],
},
}) |
Beta Was this translation helpful? Give feedback.
-
What if I only want to use a module in web3 like web3-eth-abi? |
Beta Was this translation helpful? Give feedback.
-
I'm encountering this same error using vite + vue plus the taquito library for Tezos, although I get it in the dev build as well. I've put together a minimal repo here that illustrates the error: https://github.com/mcclux/balance-debug I don't believe it's an issue with the taquito library because I can use it in a pure typescript example and it works as expected |
Beta Was this translation helpful? Give feedback.
-
Just sharing... Many web3 related package, based on my experience, they are all depended on node-polyfills, such as bip39, ed25519-hd-key, etc. Vite has a great experience when developing, but it is pity I have to use another tool which is slow/hard-to-configure. Hope vite support nodejs polyfills one day. |
Beta Was this translation helpful? Give feedback.
-
Since vite v2.8 previously separated the business code from node_modules, the dependencies will be packaged into vender file. After v2.8 the business code and external dependencies will be packaged into one file. If this configuration is still required, You need to import the splitVendorChunkPlugin yourself to support this configuration if u have a setting in vite.config.ts like me: import { defineConfig } from 'vite'
export default defineConfig({
build: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
const strArr = id.toString().split('node_modules/')
const arr = strArr[strArr.length - 1].split('/')
switch (arr[0]) {
case '@vue':
case 'ant-design-vue':
case '@ant-design':
return '_' + arr[0]
default:
// remove this
// return '__vender'
// use the default setting
return
}
}
}
... |
Beta Was this translation helpful? Give feedback.
-
Hi there, I'm encountering the following error..
can someone help me out |
Beta Was this translation helpful? Give feedback.
Using the pre-bundled
web3
script seems to workaround the problem: