11

I'm getting this error:

Error: Cannot find module 'browserify'

When I add this line to my app/server.js file:

var browserify = require('browserify');

Now I'm still new to Node, but I think I installed it correctly, via

npm install -g browserify

as per their docs.

I'm pretty sure this is the command to check my global modules:

D:\Websites\MySite> npm ls -g
C:\Users\Mark\AppData\Roaming\npm
├─┬ browserify@1.17.2
│ ├─┬ buffer-browserify@0.0.4
│ │ └── base64-js@0.0.2

It lists browserify there. So why can't I require it?

mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • 1
    Possible duplicate of http://stackoverflow.com/questions/9587665/nodejs-cannot-find-installed-module-on-windows – Duncan_m Jan 23 '13 at 04:38
  • 1
    Oh..well. Installing it without `-g` made it work... but if `-g` *doesn't* install libs globally, why do some many libraries recommend it? I mean, if it adds it to the path so you can call some of their tools via command-line, that's great, but shouldn't they be recommending you run both with and without `-g` then? – mpen Jan 23 '13 at 04:40
  • 1
    Modules are typically recommended to be installed globally when they need to be used from the command line. But any module that is `require`d from your code needs to be installed locally -- one of the reasons for this is that it allows each project to have different versions of the same module installed. – Jonathan Warden Aug 04 '13 at 23:37
  • 2
    But shouldn't globally installed modules be able to be `require`d globally, i.e. from any project/place? I think that prioritizing locally installed modules should be enough to let projects have different versions of the same module. – Gui Imamura Oct 01 '15 at 13:20
  • You want them locally installed because then other people will get the exact same version as you have. When you save the dependency in your package.json, someone else can install your project via "npm install" and get the exact same versions of your packages. If you install something globally you just can have 1 version (normally the latest) but this dependency would not get shared across other team members and thus will be missing. – Andi-lo Dec 02 '16 at 10:29

5 Answers5

15

I was face same problem but if you want to install browserify module you can use this

       npm install  browserify        
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
Anish Agarwal
  • 1,793
  • 19
  • 19
2

i have to find another way for install browserify for globally so you can use this command for linux

sudo npm install browserify -g
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
Anish Agarwal
  • 1,793
  • 19
  • 19
2

Try:

npm install js-base64

and if you encounter the below error

npm ERR! Error: EACCES: permission denied, unlink '/Users/host/module/node_modules/npm/node_modules/.bin/node-gyp'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, unlink '/Users/host/module/node_modules/npm/node_modules/.bin/node-gyp']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'unlink',
npm ERR!   path: '/Users/host/module/node_modules/npm/node_modules/.bin/node-gyp' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

then use the below command:

sudo npm install -g js-base64 --save
DILIP KOSURI
  • 455
  • 5
  • 10
0

I encountered this issue in an Angular 11 project and installing browserify didn't solve my issue but installing os-browserify did.

npm install os-browserify
Dejazmach
  • 742
  • 8
  • 15
0

I encountered this issue. I have deleted all the browserify modules from node modules and again tried:

npm install  browserify  

And now it's working. You can try this.

Ingo Steinke
  • 766
  • 3
  • 11
  • 30
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 03 '22 at 09:39