wasm_game_of_life icon indicating copy to clipboard operation
wasm_game_of_life copied to clipboard

"npm link" results in "permission denied"

Open kawogi opened this issue 7 years ago • 5 comments

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?

kawogi avatar Sep 04 '18 21:09 kawogi

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.

fitzgen avatar Sep 04 '18 21:09 fitzgen

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?

kawogi avatar Sep 04 '18 21:09 kawogi

@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.

ashleygwilliams avatar Sep 04 '18 21:09 ashleygwilliams

@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...

manast avatar Dec 04 '18 08:12 manast

Please try again through the following command line

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

I wish it could help you

HaleyLeoZhang avatar Jun 10 '19 11:06 HaleyLeoZhang