Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot convert a BigInt value to a number #6187

Closed
eliashezron opened this issue Jun 12, 2023 · 16 comments · Fixed by #6506
Closed

TypeError: Cannot convert a BigInt value to a number #6187

eliashezron opened this issue Jun 12, 2023 · 16 comments · Fixed by #6506
Assignees
Labels
4.x 4.0 related Bug Addressing a bug Discussion

Comments

@eliashezron
Copy link

eliashezron commented Jun 12, 2023

Expected behavior

view screen on deployment

Actual behavior

failing to view screen on deployment because of the error, This is the error TypeError: Cannot convert a BigInt value to a number that seems to be coming from the converter.ts file. line 40 in the screenshot below
Screenshot 2023-06-12 at 14 40 01

Steps to reproduce the behavior

  1. [First step]
    create-react-app
  2. [second step]
    install the lastest web3 package yarn add web3
  3. [third step]
    build the project
  4. [and so on...]
    deploy to netlify or vercel

Logs

Screenshot 2023-06-12 at 14 34 30

Environment

npm 9.6.2
node v18.15.0
web3js v4.0.1
OS macOS
device macbook

@Muhammad-Altabba Muhammad-Altabba added Needs Clarification Requires additional input 4.x 4.0 related labels Jun 12, 2023
@Muhammad-Altabba
Copy link
Contributor

Thanks @eliashezron for opening an issue.

However, in order to help you, we need the code that caused the error. And it will be great if you could make it available at some cloud IDE like https://codesandbox.io/.

Thanks,

@eliashezron
Copy link
Author

so I am trying to create an chrome extension, I create a reactapp and the add web3 package to the app, Then call a function to get the balance of an address, Build and deploy. Thats where the error comes from. try it out here

https://codesandbox.io/s/web3jstypeerrorcannot-convert-a-bigint-value-to-a-number-cljhk7?file=/src/App.js:772-788

@Xaber20110202
Copy link

Xaber20110202 commented Jun 15, 2023

Same problem, I just set version to 1.9.0, solved this problem. @eliashezron

@mconnelly8 mconnelly8 added the Bug Addressing a bug label Jun 20, 2023
@valentin-uskov
Copy link

valentin-uskov commented Jun 21, 2023

@eliashezron Hi!
Same problem. Change browsers list in package.json, solved this problem

"browserslist": {
    "production": [
      "chrome >= 67",
      "edge >= 79",
      "firefox >= 68",
      "opera >= 54",
      "safari >= 14"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

@eliashezron
Copy link
Author

@eliashezron Hi! Same problem. Change browsers list in package.json, solved this problem

"browserslist": {
    "production": [
      "chrome >= 67",
      "edge >= 79",
      "firefox >= 68",
      "opera >= 54",
      "safari >= 14"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

This solution worked for me. Thank you @valentin-uskov

@milaabl
Copy link

milaabl commented Jun 27, 2023

@eliashezron , indeed @valentin-uskov is a life saver! Thanks

@Edison4mobile
Copy link

@valentin-uskov
you saved my time.

@devilbcsswap
Copy link

@eliashezron Hi! Same problem. Change browsers list in package.json, solved this problem

"browserslist": {
    "production": [
      "chrome >= 67",
      "edge >= 79",
      "firefox >= 68",
      "opera >= 54",
      "safari >= 14"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

Fkkk. You saved my life. Thanks.

@Muhammad-Altabba Muhammad-Altabba added Discussion and removed Needs Clarification Requires additional input labels Aug 7, 2023
@Muhammad-Altabba
Copy link
Contributor

Thanks all for your shared findings.
We will try to look deeper into this.

@dhruv2185
Copy link

@eliashezron Hi! Same problem. Change browsers list in package.json, solved this problem

"browserslist": {
    "production": [
      "chrome >= 67",
      "edge >= 79",
      "firefox >= 68",
      "opera >= 54",
      "safari >= 14"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

Thank you very much, wasn't able to fix this bug for days. You are a lifesaver!

aidatorajiro pushed a commit to aidatorajiro/rakugaki that referenced this issue Sep 1, 2023
@mconnelly8
Copy link

Per 9/5 meeting, need to investigate.

@inspi-writer001
Copy link

@eliashezron Hi! Same problem. Change browsers list in package.json, solved this problem

"browserslist": {
    "production": [
      "chrome >= 67",
      "edge >= 79",
      "firefox >= 68",
      "opera >= 54",
      "safari >= 14"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

Thanks man, I've been on this for daysss

Finally, your solution helped me

@inspi-writer001
Copy link

also , if you're using web3.js on the baackend, say a nodejs app,

use module import Web3 from "web3" instead of const Web3 = require("web3")
this'll prevent the "Web3 is not a constructor" issue

@Muhammad-Altabba Muhammad-Altabba self-assigned this Oct 11, 2023
@moojing
Copy link

moojing commented Oct 12, 2023

@eliashezron Hi! Same problem. Change browsers list in package.json, solved this problem

"browserslist": {
    "production": [
      "chrome >= 67",
      "edge >= 79",
      "firefox >= 68",
      "opera >= 54",
      "safari >= 14"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

Fkkk. You saved my life. Thanks.

this solve my problem too!! Even I'm in other similar situation! thx.

@Muhammad-Altabba
Copy link
Contributor

Muhammad-Altabba commented Oct 12, 2023

Hi all,
This issue is because React uses babel for transpilation. And babel has issues with bigint as you can find here: babel/babel#13109
And so, not only react applications will face this issues. But also any application that uses babel unless it add the browserslist to package.json as described in the issue: babel/babel#13109 and as pointed in: #6187 (comment).

However, we will try to overcome this by avoid using ** with BigInt. So, in the next version there would be no need to add something to your package.json.

@Muhammad-Altabba Muhammad-Altabba linked a pull request Oct 12, 2023 that will close this issue
17 tasks
@Muhammad-Altabba
Copy link
Contributor

Muhammad-Altabba commented Oct 16, 2023

The code has been modified so this issue should not be present once the next release takes a place.

If anyone still face this issue, one of the following should resolve it:

However, if one of the above did not solve your issue. Please provide the full details and steps to replicate the case. And preferably provide your code at a cloude IDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug Discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.