18

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 contextify@0.1.5
6496 info postuninstall contextify@0.1.5
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 jquery@1.8.3
6501 info uninstall jquery@1.8.3
6502 verbose true,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules unbuild jquery@1.8.3
6503 info postuninstall jquery@1.8.3
6504 error contextify@0.1.5 install: `node-gyp rebuild`
6504 error `sh "-c" "node-gyp rebuild"` failed with 1
6505 error Failed at the contextify@0.1.5 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 :)

Mohammad Arif
  • 6,987
  • 4
  • 40
  • 42
  • I have fixed some package.json values now it's giving me the below issue: module.js:340 throw err; ^ Error: Cannot find module '/Repos/GIT/JavaScript-Boilerplate/link' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3 – Mohammad Arif May 03 '13 at 11:09

3 Answers3

12

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.

Community
  • 1
  • 1
Yves M.
  • 29,855
  • 23
  • 108
  • 144
7

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.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
4

This can be fixed in linux or in my case WSL by setting the global package directory to be in user space rather than root.

First create a dir for global packages

mkdir ~/.npm-packages

Then tell npm where to store globally installed packages

npm config set prefix ~/.npm-packages

Finally ensure npm will find installed binaries and man pages by adding the following to your .bashrc/.zshrc:

NPM_PACKAGES=~/.npm-packages
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
Damo
  • 5,698
  • 3
  • 37
  • 55
  • i'm a bit puzzled as to why it doesn't do something like this by default. I seem to get bit by this every time I set up a new system... – Michael Sep 23 '22 at 23:36