Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"npm link" results in "permission denied" #35

Open
kawogi opened this issue Sep 4, 2018 · 5 comments
Open

"npm link" results in "permission denied" #35

kawogi opened this issue Sep 4, 2018 · 5 comments

Comments

@kawogi
Copy link

kawogi commented Sep 4, 2018

By following the tutorial the npm link command results in a "permission denied" error message. I already purged the whole project directory and started all over. The issue remained:

$ cargo generate --git https://github.com/rustwasm/wasm-pack-template
 Project Name: wasm-game-of-life
 Creating project called `wasm-game-of-life`...
 Done! New project created /home/user/dev/wasm-game-of-life
$ cd wasm-game-of-life/
.../wasm-game-of-life$ wasm-pack init
  
  [1/8] Checking crate configuration...
  [2/8] Adding WASM target...
  [3/8] Compiling to WASM...
  [4/8] Creating a pkg directory...
  [5/8] Writing a package.json...
  :-) [WARN]: Field description is missing from Cargo.toml. It is not necessary, but recommended
  :-) [WARN]: Field repository is missing from Cargo.toml. It is not necessary, but recommended
  :-) [WARN]: Field license is missing from Cargo.toml. It is not necessary, but recommended
  [6/8] Copying over your README...
  [7/8] Installing WASM-bindgen...
  [8/8] Running WASM-bindgen...
  :-) Done in 5 minutes
| :-) Your WASM pkg is ready to publish at "./pkg".
.../wasm-game-of-life$ npm init wasm-app www
npx: installed 1 in 1.436s
🦀 Rust + 🕸 Wasm = ❤
.../wasm-game-of-life$ cd www
.../wasm-game-of-life/www$ npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 550 packages from 405 contributors and audited 6365 packages in 5.006s
found 0 vulnerabilities

.../wasm-game-of-life/www$ cd ../pkg/

.../wasm-game-of-life/pkg$ npm link
npm ERR! path /home/user/dev/wasm-game-of-life/pkg
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '/home/user/dev/wasm-game-of-life/pkg' -> '/usr/local/lib/node_modules/wasm-game-of-life'
npm ERR!  { Error: EACCES: permission denied, symlink '/home/user/dev/wasm-game-of-life/pkg' -> '/usr/local/lib/node_modules/wasm-game-of-life'
npm ERR!   stack: 'Error: EACCES: permission denied, symlink \'/home/user/dev/wasm-game-of-life/pkg\' -> \'/usr/local/lib/node_modules/wasm-game-of-life\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '/home/user/dev/wasm-game-of-life/pkg',
npm ERR!   dest: '/usr/local/lib/node_modules/wasm-game-of-life' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2018-09-04T20_55_20_981Z-debug.log

The log adds the following information:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'link' ]
2 info using [email protected]
3 info using [email protected]
4 verbose linkPkg /home/user/dev/wasm-game-of-life/pkg
5 verbose stack Error: EACCES: permission denied, symlink '/home/user/dev/wasm-game-of-life/pkg' -> '/usr/local/lib/node_modules/wasm-game-of-life'
6 verbose cwd /home/user/dev/wasm-game-of-life/pkg
7 verbose Linux 4.15.0-33-generic
8 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "link"
9 verbose node v8.10.0
10 verbose npm  v6.4.1

The message is misleading, though. The link target simply doesn't exist:

$ ls -lap /usr/local/lib/node_modules/
total 12
drwxr-xr-x  3 root   root 4096 Sep  4 22:27 ./
drwxr-xr-x  5 root   root 4096 Sep  4 22:27 ../
drwxr-xr-x 10 nobody user  4096 Sep  4 22:27 npm/

Did I miss a step?

@fitzgen
Copy link
Member

fitzgen commented Sep 4, 2018

Aha! I'm using nvm to manage node/npm installs so my global package install dir is under my home dir and owned by me.

With your setup, you'll have to do sudo npm link to make this work, I believe.

@kawogi
Copy link
Author

kawogi commented Sep 4, 2018

Thanks for your quick reply.
sudo fixes the problem, but it feels odd to require elevated permissions for a build-like task.
Can that global package install dir be redirected to home?

@ashleygwilliams
Copy link
Member

@fyl2xp1 you'll want to check this out: https://docs.npmjs.com/getting-started/fixing-npm-permissions

the tl;dr is you can reinstall node using a version manager (i know it sounds like a lot but this is the preferred method!) or you can change the default directory manually... both of those are documented in the above link.

@manast
Copy link

manast commented Dec 4, 2018

@ashleygwilliams thing is that it installing node using a version manager requires node to begin with, which already has been wrongly installed requiring sudo. So after installing a different version of node using n for example, you are still in square one, at least thats my problem on a Mac, Mac OS Mojave...

@HaleyLeoZhang
Copy link

Please try again through the following command line

npm install --unsafe-perm=true --allow-root

I wish it could help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants