I am trying to require the NPM package browserify
, which I have installed globally through this command:
npm install -g browserify
This is the file bundle.js
in which I try to require browserify:
var browserify = require('browserify');
var fs = require('fs');
var b = browserify();
var outputFileStream = fs.createWriteStream('./test_bundle.js');
b.add('index.js');
b.bundle().pipe(outputFileStream); // process.stdout
When I do node build.js
I get this error:
Error: Cannot find module 'browserify'
( etcetera...)
If I then instead install browserify locally:
npm install -g browserify
I get no error and the build goes just fine.
I have uploaded a small demo program to this Github repository:
https://github.com/loldrup/test_require
So if you're on a Windows 7 machine, you should be able to reproduce my error simply by cloning:
git clone https://github.com/loldrup/test_require
and running:
node build
EDIT:
even after adding relevant node paths to my system variable 'path', and restarted the command promt, I still can't require globally installed node modules:
Node.js doesn't look in the folder where global modules are installed by default.
Add module.paths.push(' path to global node_modules ') at the beginning of the script or set up the enviroment variables .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.