During the compilation of my JS code I used the statement Web3 = require('web3') for importing the web3 library. But since the require function doesn't work in a web application, I would like to know how it can be done.


3 Answers 3


by web application you mean HTML/..

download web3js form github repo.

you could load it as normal js file using

<script src="web3js_path"></script>


    <script type="text/javascript" src="web3.min.js"></script>

   <script type="text/javascript">  if(typeof window.web3 !== "undefined" && typeof window.web3.currentProvider !== "undefined") {
        var web3 = new Web3(window.web3.currentProvider);
      } else {
        var web3 = new Web3();

You can add it to your client code using package managers like bower:

bower install web3

or Component

component install ethereum/web3.js

or simply include distributed and minified library web3.min.js in your html file:

<script src="PATH/web3.min.js"></script>

The current answers detail how to include web3.js - a standalone Javascript file.

Your question implies that you are using a package manager - npm perhaps?

To pull in required packages, and utilise them within the browser you can utilise a tool like browserify or webpack.

Your question is however lacking in details so I am just making assumptions..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.