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

TypeError: Cannot read property 'slice' of undefined

Open ghost opened this issue 8 years ago • 6 comments

I have installed web3 using npm. When I import web3 in my react application I get the error "TypeError: Cannot read property 'slice' of undefined"

Following are the version of packages I am using in my application "webpack": "2.6.1", "webpack-dev-server": "2.4.5", "web3": "^1.0.0-beta.36", npm: 5.6.0, node: 8.11.4

screenshot from 2018-11-20 17-03-31

ghost avatar Nov 20 '18 13:11 ghost

Please put the related code snippet.

Aniket-Engg avatar Nov 23 '18 05:11 Aniket-Engg

When I import web3 in my application (Import Web3 from 'web3' ) and run it, I get the above one error. But when I downgrade web3js to 0.20.6. It works fine.

ghost avatar Nov 23 '18 11:11 ghost

Hi @awprasad could you elaborate a bit on the issue?

After import Web3 from 'web3' do you call Web3?

Also please note that since web3 v1.0.0 is a major version upgrade, it contains breaking changes. If you have code in your application that is using the old version 0.20.6 of Web3, you will have to refactor your code to work with the new updated web3 library

huanzhang89 avatar Nov 30 '18 14:11 huanzhang89

@awprasad possibly you are not checking the nullity condition. Ex: If you have an array, and you want to apply slice method over it, you also have to check for existence of some element inside array may be using array.length

ctrlaltvikas avatar Dec 08 '18 15:12 ctrlaltvikas

Closed because of the ongoing clean up of the issue list. Feel free to ask this in our gitter channel or on stackoverflow.

nivida avatar Apr 16 '19 09:04 nivida

i had the same issue

i tried uninstall and reinstall web3, worked ...

Malek-Ayadi avatar Jul 14 '20 15:07 Malek-Ayadi