Browserify + NodeJS [node: File or directory not found]

Posted on

Question :

Situation

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

Environment

I have the NodeJs, NPM and Browserify installed on my ubuntu machine, the module I want is in node_module/uniq

Main.js

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

Command

I give the following command to write browser-based code

browserify main.js -o bundle.js

It returns me this

Error

  

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

    

Answer :

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

sudo apt-get install nodejs-legacy

I could not solve by creating symbolic links, I do not know if my example applies to this situation, but maybe it helps.

link

    

By typing only the env command you can see all variables used by it. Search for PATH, do:

env | grep -e '^PATH'

It will show 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

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

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

I hope I have helped.

    

Solution

The error was 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

Note that nodejs is written without JS node , I changed it to nodejs .
Changing

#!/usr/bin/env nodejs

I ran the following command again

browserify main.js -o bundle.js

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

I found the solution thanks to the atilacamurca that put up the problem of path. Thanks!

    

I managed to solve this, just copying the nodejs with the node name, this I did in Ubuntu 14.04, the correct one was to use mv to rename the nodejs but I was afraid to shit something I just copied. >

Example:

cd /usr/bin
sudo cp nodejs node

Ready just this, after that everything worked normally. So far everything is responding normal.

    

Clarification

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

Workaround

I used this tool online, where I insert the module I want from nodejs and it returns the code in a way that the browser can interpret.

Tool link: link

    

Leave a Reply

Your email address will not be published. Required fields are marked *