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

App.js not running properly on the client side #21

Open
lasborne opened this issue Feb 19, 2022 · 5 comments
Open

App.js not running properly on the client side #21

lasborne opened this issue Feb 19, 2022 · 5 comments

Comments

@lasborne
Copy link

Goodday, Web3 devs and learners, I am having this persistent issue for some days now. Each time i'm following up the tutorial on Intro To Ethereum programming [Full Course] at about 7hrs:14mins.
I tried running the app.js file by doing npm run dev. It runs smooth but returns this error on inspection
Uncaught (in promise) TypeError: Web3 is not a constructor
at Object.loadWeb3 (bundle.js:85130:20)
at Object.load (bundle.js:85122:19)
at bundle.js:85167:13
at dispatch (jquery.min.js:3:12444)
at r.handle (jquery.min.js:3:9173)

Note: The bundle.js is actually a browserified version of app.js, since require() doesn't apply smoothly to client-side JS, i had to create a browserified version of my original app.js file by running the command browserify app.js -o bundle.js

But, on clicking on the resulting error above, i noticed that the error is actually centered on any line with web3 as shown below
App = {
load: async () => {
await App.loadWeb3()
await App.loadAccount()
},
// https://medium.com/metamask/https-medium-com-metamask-breaking-change-
loadWeb3: async () => {
if (typeof web3 !== 'undefined') {
App.web3Provider = web3.currentProvider
web3 = new Web3(web3.currentProvider)

These errors were about 3 before now, but i've been able to debug the other 2, remaining this, and would appreciate a solution or input

@lasborne
Copy link
Author

Okay, i finally found a way of going through the issue i posted above by following issue #19 updates posted by @ahampriyanshur. But then again, i have run into another issue of ethereum not defined

@iamthekavita
Copy link

I am also facing the same issue.
Uncaught TypeError: Web3 is not a constructor
Uncaught (in promise) ReferenceError: Web3 is not defined

any help or solutions are appreciated.

@lasborne
Copy link
Author

@iamthekavita
try inserting this <script src="vendor/web3/dist/web3.min.js"></script> in your html before the <script src="vendor/truffle-contract/dist/truffle-contract.js"></script>
i.e., it should be something like this below for your scripts

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
    </script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    **<script src="vendor/web3/dist/web3.min.js"></script>**
    <script src="vendor/truffle-contract/dist/truffle-contract.js"></script>
    <script src="app.js"></script>

@lasborne
Copy link
Author

Sorry, use this,
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="vendor/web3/dist/web3.min.js"></script>
<script src="vendor/truffle-contract/dist/truffle-contract.js"></script>
<script src="app.js"></script>

@gurkankaya05
Copy link

@iamthekavita try inserting this <script src="vendor/web3/dist/web3.min.js"></script> in your html before the <script src="vendor/truffle-contract/dist/truffle-contract.js"></script> i.e., it should be something like this below for your scripts

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
    </script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    **<script src="vendor/web3/dist/web3.min.js"></script>**
    <script src="vendor/truffle-contract/dist/truffle-contract.js"></script>
    <script src="app.js"></script>

thanks! This worked for me.

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