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

Uncaught ReferenceError: Web3 is not defined #1233

Closed
Alex-Gorbach opened this issue Dec 15, 2017 · 3 comments
Closed

Uncaught ReferenceError: Web3 is not defined #1233

Alex-Gorbach opened this issue Dec 15, 2017 · 3 comments

Comments

@Alex-Gorbach
Copy link

Alex-Gorbach commented Dec 15, 2017

Hello! I'm trying to create an instance of web3 using the following code in the index.js file:
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
But have an error:
screenshot 4
I have installed Web3 and started the testrpc.
When I execute this code in the node.js terminal , there are no errors.
Why is this happening? Thanks.

@nisdas
Copy link
Contributor

nisdas commented Dec 17, 2017

Most likely you did not import the web3 library using this : var Web3 = require("web3")
Do that and you should be fine

@Alex-Gorbach
Copy link
Author

var Web3 = require("web3") also produced an error: "Uncaught ReferenceError: require is not defined".
I solved this problem using the following construction from here:
if (typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); } else { // set the provider you want from Web3.providers web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); }
Thanks.

@ddb1
Copy link

ddb1 commented Apr 3, 2021

i have also meet this problem ,who can tell me how to solve it. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants