25

Quick question, when I run browserify index.js -o app.js from mac terminal, I get command not found. I have done npm install -g browserify but still no luck. Any idea why I am getting this?

Thank you

It was easier for me to do a gist than to paste here: https://gist.github.com/pertrai1/4ccf77e7b31cb5628b5d

pertrai1
  • 4,146
  • 11
  • 46
  • 71

9 Answers9

19

Just install it in a global space like this if you need to run it from the command line.

npm install browserify -g

You may need to run

npm uninstall browserify -g fist just to be sure you don't have false aliases.

prosti
  • 42,291
  • 14
  • 186
  • 151
9

Add this to your ~/.bashrc or equivalent:

export PATH=$PATH:~/.npm-global/bin/

Then, to actually have this take effect in your terminal session, execute source ~/.bashrc.

At this point you can execute browserify, as well as potentially many other commands. Check out ~/.npm-global/bin/ to see what's become available.

jjpe
  • 664
  • 4
  • 13
2

I could not get browserify to work either.

Running ~/.npm/bin/browserify does work.

Other packages seem to run fine (phantomjs for instance).

A workaround fix seems to be adding alias browserify='~/.npm/bin/browserify' to your .bash_profile

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Janvdm
  • 21
  • 2
2

It is an old post but I believe people are still facing the same problem, like me.

This was how I solved my problem:

<your project folder>/node_modules/browserify/bin/cmd.js main.js -o bundle.js
1

If you install locally npm install browserify, you can use this method to execute the browserify command.

node_modules/.bin/browserify

For example: broweserify command example

Extra tips:

Add this command to your packages.js file:

...
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "bundle": "node_modules/.bin/browserify index.js > bundle.js"
  },

Then everytime you want to bundle you file just hit npm run bundle

Hope it helps you guys out there..

Haziq Musa
  • 31
  • 2
0

If for some reason the browserify command has not been installed at all (can happen for example if you're running Homebrew on old unsupported Mac OS X versions), an alternative is to call it via node, for example:

export NODE_PATH=/usr/local/share/npm/lib/node_modules
node -e 'require("browserify")("input.js").bundle().pipe(fs.createWriteStream("output.js"))'
Silas S. Brown
  • 1,469
  • 1
  • 17
  • 18
0

As a Mac user I had to add

export PATH=$PATH:/usr/local/Cellar/node/13.6.0/bin/

in ~.bash_profile

Why Cellar path i dont know.

luky
  • 2,263
  • 3
  • 22
  • 40
0

I'm using the default zsh shell and I came across a solution: sudo npm install browserify -g

After that sudo browserify AND browserify worked flawlessly. I guess mine was a simple permissions issue.

I'm running Ventura.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34308041) – Wongjn May 04 '23 at 23:31
0

This is my solution to solve it within project directory, not by global

npm install browserify
npx browserify main.js -o bundle.js
Tyler2P
  • 2,324
  • 26
  • 22
  • 31