web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Uncaught TypeError - React Project

Open dillonsvincent opened this issue 4 years ago • 7 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

Browsers logging Uncaught TypeError on web3.js load (chrome and safari)

I'm using v1.8.0 in a react project, this error is only happening on react builds not in development.

web3.min.js:29092 Uncaught TypeError: Super expression must either be null or a function
    at web3.min.js:29092:1
    at web3.min.js:29091:1
    at Object.i (web3.min.js:29090:1)
    at Object.<anonymous> (web3.min.js:29246:8)
    at Object.<anonymous> (web3.min.js:29247:6)
    at r (web3.min.js:14:1)
    at Object.<anonymous> (web3.min.js:28066:1)
    at r (web3.min.js:14:1)
    at Object.<anonymous> (web3.min.js:22734:1)
    at r (web3.min.js:14:1)

Expected Behavior

No console errors when loading page

Steps to Reproduce

Use web3 v.1.8.0 in a react project Use Node v14 Build Project

Web3.js Version

1.8.0

Environment

  • Operating System: Mac M1 Chip
  • Browser: Chrome
  • Node.js Version: 14.15.4
  • NPM Version: 6.14.10

Anything Else?

No response

dillonsvincent avatar Oct 16 '22 00:10 dillonsvincent

Hey, sorry that you are facing this issue. What does your react package.json look like?

luu-alex avatar Nov 06 '22 23:11 luu-alex

Hey there, I was able to get the build sucesfully running with node - v14.21.1 and npm - 6.14.17. If you are still facing issues id suggest upgrading your npm and node and web3 to 1.8.1. Ill be closing this issue but if anything comes up feel free to add more information, thank you

luu-alex avatar Nov 11 '22 21:11 luu-alex

Hey @luu-alex, I am facing the same issue with node - v16.14.0 and npm - v8.3.1 These are the dependencies in my package.json. The issue occurs only when I serve a build, not during development.

  "dependencies": {
    "axios": "^0.27.2",
    "big-number": "^2.0.0",
    "bootstrap": "^5.1.3",
    "react": "^18.0.0",
    "react-bootstrap": "^2.2.3",
    "react-bootstrap-sidebar-menu": "^2.0.3",
    "react-dom": "^18.0.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "^2.1.3",
    "typescript": "^4.6.3",
    "web3": "^1.7.4"
  },

madhavappaneni avatar Nov 30 '22 19:11 madhavappaneni

@madhavappaneni thank you for the reply, have you tried upgrading web3 to version 1.8? as well what is the error

luu-alex avatar Nov 30 '22 19:11 luu-alex

@luu-alex - Here is the complete error with the stack trace. I will try upgrading to web3 1.8.

Uncaught TypeError: Super expression must either be null or a function
    at web3.min.js:25038:1
    at web3.min.js:25037:1
    at Object.i (web3.min.js:25036:1)
    at Object.<anonymous> (web3.min.js:25192:8)
    at Object.<anonymous> (web3.min.js:25193:6)
    at r (web3.min.js:13:1)
    at Object.<anonymous> (web3.min.js:24116:1)
    at r (web3.min.js:13:1)
    at Object.<anonymous> (web3.min.js:19276:1)
    at r (web3.min.js:13:1)

madhavappaneni avatar Nov 30 '22 19:11 madhavappaneni

@luu-alex - I am getting the same error with web3 v1.8.1 as well.

madhavappaneni avatar Nov 30 '22 19:11 madhavappaneni

@madhavappaneni Hey there I was able to get npm run build working with a create-react-app project using node v16.18.1 (npm v8.19.2),

  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4",
    "web3": "^1.8.1",
  },

can you provide me a code snippet of how ur using web3? thatll be extremely helpful

luu-alex avatar Nov 30 '22 19:11 luu-alex