1

I'm installing a new project and upon npm install I get the error below. I have tried the solution here, but that made no difference. Entering those lines in the terminal produced no output and npm install after that resulted in the same error. Any idea how to solve this?

Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/5134a7c3'd in 126ms

Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/fcf123f8'^1.1.7 fetched in 96ms

Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/f8a35f38'd in 39ms

Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/3914ffcc'4ms

Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/98bb7e0d'tched in 65ms

Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/5196be2e'63ms

Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/1cf3fdde'fetched in 394ms

npm WARN checkPermissions Missing write access to /projects/user-portal/node_modules
npm WARN checkPermissions Missing write access to /projects/user-portal/node_modules/@google-cloud
npm WARN bookshelf@0.10.4 requires a peer of knex@>=0.6.10 <=0.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.3.1 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.3.1 requires a peer of popper.js@^1.14.7 but none is installed. You must install peer dependencies yourself.
npm WARN portal@1.0.0 license should be a valid SPDX license expression

npm ERR! path /projects/user-portal/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/projects/user-portal/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/projects/user-portal/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/projects/user-portal/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/projects/user-portal/node_modules' }
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).

Update I tried sudo chown -R user:user /projects/ and then npm install, but this resulted in the following error:

sharp@0.18.4 install /projects/user-portal/node_modules/sharp
node-gyp rebuild

gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack     at getNotFoundError (/usr/lib/node_modules/npm/node_modules/which/which.js:13:12)
gyp ERR! stack     at F (/usr/lib/node_modules/npm/node_modules/which/which.js:68:19)
gyp ERR! stack     at E (/usr/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Linux 3.10.0-957.21.3.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /projects/user-portal/node_modules/sharp
gyp ERR! node -v v8.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Marty
  • 2,132
  • 4
  • 21
  • 47
  • 1
    what is the result of these two command? `whoami` and `ls -la /projects`. It's better to create project on your home directory. – agtabesh Jul 04 '19 at 21:28
  • Thanks, `whoami` returns `user`. And `ls -la /projects` returns: `total 4` `drwxr-xr-x 3 user root 25 Jul 4 20:46 .` `drwxr-xr-x 22 root root 295 Jul 4 21:45 ..` `drwxr-xr-x 18 user user 4096 Jul 4 21:18 user-portal` I'm using an IDE (Codenvy) which is why the project is in a sub-folder of the workspace. – Marty Jul 04 '19 at 21:48
  • 2
    is make installed? quick check would be `make -v` – Software Person Jul 04 '19 at 22:11
  • Ah, it indeed wasn't and not it runs! Thank you! – Marty Jul 04 '19 at 22:15

2 Answers2

3

I just super user do it:

sudo npm install -g

for global stuff

and just:

sudo chown -R [user]:[user] /projects/ 

or create a 'projects' group and add yourself to that group and make that group own it.

Although, if I were you I'd just move your projects to your home directory like @agtabesh suggested.

Software Person
  • 2,526
  • 13
  • 18
  • Thanks, I updated the OP with the result from this suggestion. I prefer not to use sudo here and unfortunately it's not possible on Codenvy to move projects to the home directory. – Marty Jul 04 '19 at 22:03
  • sudo also helped me for local stuff installs – PokatilovArt Jan 26 '22 at 20:40
  • Using super user to install global packages is terrible advice considering modern npm install paths are by default in `/usr/local/` – myol Jun 23 '23 at 08:36
3

run this line first:

sudo chown -R $USER /usr/local/lib/node_modules

explanation:

https://flaviocopes.com/npm-fix-missing-write-access-error

zc-code
  • 39
  • 1