2
votes

I am trying to deploy my project which needs the web3 Javascript API. As done by some examples I found online, I need to do the following:

<script type="text/javascript">
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
...code... </script>

When I run the project i get this error "Uncaught ReferenceError: require is not defined". I've already done "meteor add modules", meteor add aramk:requirejs, sudo npm install require and sudo npm install requirejs. I downloaded and included the js file (through templating since in meteor js files are handled differently). What am I missing?

1
What version of Meteor are you using? Do you have ecmascript or babel in your list of packages (.meteor/packages) - Mikkel
Thank you for your input! meteor version 1.1.0.2. Yes I have them both - PetrosM
That's a very old version of Meteor, and it may be impossible to do what you want with that version. Also usually you should have only one of ecmascript/babel, because they do similar things - Mikkel
Yes my bad. That was in another project i was trying out with yo-man and automatically installed and old version of meteor. my version for this project is up to date v1.4.2.3 - PetrosM

1 Answers

3
votes

I see that you use require inside a script tag so I think this code is in a html file. If that's so, you will need to move that code to a js file because require can not be used in html file.