Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs npm package | npm link issue

Tags:

node.js

npm

I am trying to make a npm package (plugin) to install the little JS framework through node, have come up with the required package.json as well.

After running the npm link command on Mac terminal, got to see the following errors.

npm ERR! Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR!  { [Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Repos/GIT/JavaScript-Boilerplate' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "link"
npm ERR! cwd /Repos/GIT/JavaScript-Boilerplate
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Repos/GIT/JavaScript-Boilerplate
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Repos/GIT/JavaScript-Boilerplate/npm-debug.log
npm ERR! not ok code 0

P.S. I am pretty new to nodejs but have strong experience in JavaScript, let me know if you need more detail around.

EDIT - Got to resolved the issues given above but now getting more issues as below:

6495 verbose false,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/node_modules unbuild [email protected]
6496 info postuninstall [email protected]
6497 verbose about to build /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery
6498 info /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery unbuild
6499 verbose from cache /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/package.json
6500 info preuninstall [email protected]
6501 info uninstall [email protected]
6502 verbose true,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules unbuild [email protected]
6503 info postuninstall [email protected]
6504 error [email protected] install: `node-gyp rebuild`
6504 error `sh "-c" "node-gyp rebuild"` failed with 1
6505 error Failed at the [email protected] install script.
6505 error This is most likely a problem with the contextify package,
6505 error not with npm itself.
6505 error Tell the author that this fails on your system:
6505 error     node-gyp rebuild
6505 error You can get their info via:
6505 error     npm owner ls contextify
6505 error There is likely additional logging output above.
6506 error System Darwin 12.3.0
6507 error command "node" "/usr/local/bin/npm" "link"
6508 error cwd /Repos/GIT/JavaScript-Boilerplate
6509 error node -v v0.10.4
6510 error npm -v 1.2.18
6511 error code ELIFECYCLE
6512 verbose exit [ 1, true ]
    enter code here
    enter code here

Looks like I am close to it :)

like image 259
Mohammad Arif Avatar asked May 03 '13 10:05

Mohammad Arif


People also ask

Why npm link not working?

To fix this, use node -v in each project and check the running version of node. Use nvm install x.x.x & nvm use x.x.x to match them up. Afterward, delete your node_modules , delete your package-lock. json , re-run npm i , and re-run npm link in your dependency folder and npm link myDependency in your project folder.

What is Symlinks npm?

A symlink, short for symbolic link, is a shortcut that points to another directory or file on your system. Tell the application to use the global symlink with npm link some-dep .


2 Answers

Permissions you used when installing Node will be required when doing things like writing in your npm directory (npm link, npm install -g, etc.).

You probably ran node installation with root permissions, that's why the global package installation is asking you to be root.


Solution 1: NVM

Don't hack with permissions, install node the right way.

On a development machine, you should not install and run node with root permissions, otherwise things like npm link, npm install -g will need the same permissions.

NVM (Node Version Manager) allows you to install Node without root permissions and also allows you to install many versions of Node to play easily with them.. Perfect for development.

  1. Uninstall Node (root permission will probably be required).
    • To remove all previously installed npm global modules, see those answers.
  2. Then install NVM following instructions on this page.
  3. Install Node via NVM: nvm install stable

Now npm link, npm install -g will no longer require you to be root.


Solution 2: Install packages globally for a given user

Don't hack with permissions, install npm packages globally the right way.

If you are on OSX or Linux, you can create a user dedicated directory for your global package and setup npm and node to know how to find globally installed packages.

Check out this great article for step by step instructions on installing npm modules globally without sudo.

See also: npm's documentation on Fixing npm permissions.

like image 188
Yves M. Avatar answered Oct 11 '22 21:10

Yves M.


The easiest way to solve this would be to run the same command again using sudo:

sudo npm link

Please don't change the owner of the /usr/local directory, as this might a) have further implications on installed application and b) might compromise the security on your system. Using sudo is the right way to solve this.

like image 29
nwinkler Avatar answered Oct 11 '22 19:10

nwinkler