Browserify + Nodejs [Node: File or directory not found]

Asked

Viewed 6,659 times

6

Situation

I’m developing an extension for Google Chrome, and I need to use some Nodejs modules so I found the Browserify tool so I can add modules to use it in the browser

Ambience

I own Nodejs, NPM and Browserify installed on my Ubuntu machine, module I wish is on node_module/uniq

Main.js

var unique = require('uniq');
var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];
console.log(unique(data));

Commando

I give the following command to write browser-based code

browserify main.js -o bundle.js

he returns it to me

Error

/usr/bin/env: Node: File or directory not found

5 answers

12


I had this same problem, installed it here and solved (:

sudo apt-get install nodejs-legacy

I couldn’t solve by creating symbolic links, I don’t know if my example applies to this situation, but maybe it will help.

https://github.com/joyent/node/issues/3911

3

Typing only the command env it is possible to see all variables used by it. Search for PATH, do:

env | grep -e '^PATH'

He’ll show you something like:

PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/android-studio/sdk/platform-tools:/usr/local/android-studio/sdk/tools

Node must be in one of these directories. I do so, put Node in /usr/local/lib, then create a symbolic link on /usr/local/bin.

ln -s /usr/local/lib/node/bin/node /usr/local/bin/node

I hope I’ve helped.

2

Solution

The error was found in the cms.js file of the Browserify module.

sudo gedit /usr/local/lib/node_modules/browserify/bin/cmd.js

In line 1 we find the following

#!/usr/bin/env node

Noting that the nodejs is written without the JS node, I changed him to nodejs. Altering

#!/usr/bin/env nodejs

I executed the following command again

browserify main.js -o bundle.js

And it turns my main.js dependencies into codes that can be executed by the browser!

I found the solution thanks to the atilacamurca that put up there the path problem. Thank you!

1

I managed to solve this, just copying the nodejs with the name Node, that I did in Ubuntu 14.04, the correct was to use the mv to rename the nodejs but I was afraid to shit something there copied only.

Example:

cd /usr/bin
sudo cp nodejs node

Ready just that, after that everything worked normally. So far ta all normal responding.

0

Clarification

I have not yet found a solution to this problem, I have tested it in many ways and in other OS. I must be doing something wrong in the process.

Alternative Solution

Went to use this tool online, where I insert the module I want of the nodejs and it returns the code to me in a way that the browser can interpret.

Tool link: http://wzrd.in/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.