I installed it and am trying to use the w3 module (on windows).
I have altered my global repo location to: C:\Users\<user>\.node_modules_global
and installed the web3 module with the command bellow, which created a new folder on the node_modules_global folder:
npm install ethereum/web3.js --global
When I try to run:
Web3 = require('web3')
it, I get an
Error: Cannot find module 'web3'
however, if I use the fullpath:
Web3 = require('C:\\Users\\<user>\\.node_modules_global\\node_modules\\web3')
It works.
Any idea what could be causing this issue? (I have added C:\\Users\\<user>\\.node_modules_global
to the SYSTEM PATH).
Your installing it globally, so it is saved to your user folder, rather than in the project, and node is configured by default to look in node_modules
.
Two options to fix this:
npm install ethereum/web3.js
or npm install ethereum/web3.js --save
to install it to the node_modules
directory within your project. (You must have cd'd into your project folder first!)"NODE_PATH": "C:\\Users\\<user>\\.node_modules_global\\node_modules"
npm install my-module
, or if you'd also like to add it to your package.json, then do npm install my-module --save
npm install my-module --global
You should:
Source: https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/
You can set the NODE_PATH
environment variable to your own value, and your application will by default look there, instead of the projects node_modules
directory.
See here: http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders