termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.28k stars 3.06k forks source link

npm install: Unhandled rejection Error: EACCES: permission denied #1192

Closed christianrondeau closed 7 years ago

christianrondeau commented 7 years ago

I have created an issue here https://github.com/npm/npm/issues/17480 and @whao created an issue here https://github.com/npm/npm/issues/17480 - both are the same thing, and it's getting no traction from the npm community, so I'm trying here since it's only happening in Termux.

I think there's something weird happening there, since it's trying to symlink between two folders in the home folder... but it's still complaining about permission issues. I spent some serious time trying to figure out the problem, but the npm code is not easy to follow. You'll find more information in the ticket itself: https://github.com/npm/npm/issues/17480

Here's the original ticket content. Any ideas for me to explore are welcome, since npm is pretty central to my workflow.

important the issue does not happen with the version bundled with nodejs, which is 3.10.10 today. It's only happening with the 5.x versions.


I'm opening this issue because:

What's going wrong?

Running this (or any global/local package for that matters) using npm 5.0.3 or 5.0.4:

npm i -g npm

fails like this:

> npm i -g npm --verbose

npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli   '/data/data/com.termux/files/usr/bin/npm',
npm verb cli   'i',
npm verb cli   '-g',
npm verb cli   'npm',
npm verb cli   '--verbose' ]
npm info using npm@5.0.3
npm info using node@v6.11.0
npm verb npm-session 3b7ba2a77f7e848c
Unhandled rejection Error: EACCES: permission denied, link '/home/.npm/_cacache/tmp/6a547224' -> '/home/.npm/_cacache/content-v2/sha512/d8/e0/f8cb9554c1f6f974b32fe943e4df8353fca3cb4843dbeda6fe0d88d14eb91bec5d23ddde1751af76721044d662b479ec4c9df9f0bfcce592bbc9fc2b6f72'
    at Error (native)

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/.npm/_logs/2017-06-28T00_20_47_543Z-debug.log

The only two things included in the log that are not in the message:

5 silly install loadCurrentTree
6 silly install readGlobalPackageData

I then tried uninstalling node, deleting everything and re-installing everything and I could install the latest npm version successfully (from 3.10.10 to 5.0.4), but after that I have the same problem installing grunt-cli or bower.

I have the same issue with local packages (e.g. npm i in a project with a valid package.json or npm i gulp), and the same two additional lines in the log file.

Note that there's no such thing as sudo, everything runs under the same user in Termux. Also, since Termux does not have root access to Android, everything runs under /data/data/com.termux/files/, e.g. ~ is /data/data/com.termux/files/home, and node lives under /data/data/com.termux/files/usr/bin/node. This was not an issue before, but here are some useful links if that helps:

This being said, the issue is happening at runtime, and the printed paths in the error message are correct.

Let me know if I can provide additional details.

How can the CLI team reproduce the problem?

  1. Get your hands on Termux on any Android device 2 apt install nodejs
  2. npm i -g npm@latest
  3. Enter a folder (e.g. mkdir test && cd test), optionally doing an npm init though that's not required
  4. npm i gulp (you can try a global or a local install)

supporting information:

Jehanramadhan commented 7 years ago

when i first install nodejs and npm, npm running well. but, after i upgrade my npm with this command npm i -g npm i got error like you. to solve this problem, i installed yarn as my javascript package manager.

christianrondeau commented 7 years ago

@Jehanramadhan that's actually a good idea :)

christianrondeau commented 7 years ago

Finally found the problem and a workaround:

proot --link2symlink npm i -g npm

The problem is that termux does not support hardlinks. So any system that only allows symlink will fail.

I won't have time to propose an upstream fix soon, so in the meantime there's at least a workaround. I guess we could also patch npm...

christianrondeau commented 7 years ago

My workaround works only partially. Using this with npm i still happily throws ENOENT for every package

mattacular commented 7 years ago

I am having this same problem on ChromeOS using nodejs-current termux package (npm 5.3.0). That proot workaround works for most packages I've tried so far. Still having issues installing certain things (eg. bcrypt) but the errors are different and probably unrelated to this issue.

jayzzz00 commented 7 years ago

Creating configuration file ionic.config.json - done! [INFO] Installing dependencies may take several minutes!

npm install ✖ Running command - failed! [ERROR] An error occurred while running npm install (exit code 1):

    Unhandled rejection Error: EACCES: permission denied, open 
    '/home/jays/.npm/_cacache/tmp/e3e6f00e'
    Unhandled rejection Error: EACCES: permission denied, open 
    '/home/jays/.npm/_cacache/tmp/76d075ca'
    npm ERR! cb() never called!

    npm ERR! This is an error with npm itself. Please report this error at:
    npm ERR!     <https://github.com/npm/npm/issues>

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/jays/.npm/_logs/2017-08-31T08_34_56_417Z-debug.log

npm running command failed during creating new project

esanchma commented 7 years ago

I installed nodejs-current and tried npx signalhub and I get EACCES in the link operation too. Wrapping that with proot as suggested makes lstat fail with EPERM.

codgician commented 7 years ago

Same issue with nodejs-current node -v prints 8.4.0. npm -v prints 5.3.0.

christianrondeau commented 7 years ago

I think more information can be found here: https://github.com/golang/dep/issues/947

These issues seem to have the same core issue: hardlinks not being supported (enough) on AUFS and in Termux.

Something similar was found in OpenSSH on Termux, here's how it was fixed: https://github.com/termux/termux-packages/commit/6bbba8f22a14ec12e942950417414be0e67620ea

Hope that helps.

T-vK commented 7 years ago

Can someone explain to me why npm i worked just fine for me with nodejs, but with nodejs-current it doesn't? Does nodejs-current come with a different version of npm? And does this different version do something with symlinks which the old npm did not do? Couldn't we just install an old version of npm then? I mean the version of npm shouldn't really matter, right? I mean they all point to the same repository, so you'd essentially get the same stuff, right?

christianrondeau commented 7 years ago

@T-vK nodejs 6.0 indeed comes with an older version of npm, and it's starting with version 5 that this "issue" began happening. In other words, the issue is just with npm version 5 and up, and it comes by default with nodejs 8+ (current). You can use yarn, but you'll have to manually fix shebangs...

T-vK commented 7 years ago

I don't really know what yarn is. I'd much rather just use an old version of npm. Any idea how I could install npm version <5, but keep nodejs-current?

christianrondeau commented 7 years ago

Yarn is just another package manager: https://yarnpkg.com/en/ (it won't "just work" anyway, you'll have to fight a little bit with it!) - You can see my post here: https://github.com/termux/termux-packages/issues/853 for an idea.

As for installing an older version of npm, I guess you could do something like npm install -g npm@1.4.3 but since npm doesn't work... :P In the meantime, I don't really have a good solution for you. This is where things are expected to happen, but since npm relies on hardlinks, and using proot doesn't "just work" either", I'm also stuck: https://github.com/npm/npm/issues/17480

mattacular commented 7 years ago

I was having a similar issue because I had already installed the regular nodejs package before installing nodejs-current. Uninstalling both and then reinstalling nodejs-current fixed.

T-vK commented 7 years ago

My workaround for now: Instead of npm i, do this:
packages install nodejs -y && npm i && packages install nodejs-current -y
It will obviously take quite a bit longer than a normal npm i, but hey, at least you don't get any errors and don't have deal with a different package manager.

TheDiamondYT1 commented 7 years ago

idk why people dont use apt. it's quicker to type

bestvow commented 7 years ago

keep watching this problem ! Hope fixed quick

Auxilus commented 7 years ago

Got same issue when installing http-server using package nodejs-current

[01:48] ~ > npm install http-server --global
Unhandled rejection Error: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/a62d0816' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/6e/80/8040ea20747c25f0e31a6782d61a4f2017e677d3f1ed3bad1c8379c4f37ea8b90f7c0fae377780a9e759da90a864bfef9e95ede289c9691b43bca4006384'
                                                                                   npm ERR! cb() never called!                                                        
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://github.com/npm/npm/issues>                                   
npm ERR! A complete log of this run can be found in:
npm ERR!     /data/data/com.termux/files/home/.npm/_logs/2017-10-27T20_18_08_311Z-debug.log
christianrondeau commented 7 years ago

I think the problem should be solved upstream https://github.com/npm/npm/issues/17480 unless someone figures out a way to fully emulate hardlinks. For godep https://github.com/golang/dep/issues/947 there is a similar issue for which the solution is to change godep code...

So, workarounds and patches should go here but the fix will only happen upstream.

karolba commented 7 years ago

It seems like the only reason npm's cache uses hardlinks is to simplify, or make more atomic, the operation of moving a file (rename()ing it). A patch fixing this issue is present in #1701. I have also sent a PR upstream to zkat/cacache#110.

fornwall commented 7 years ago

The patch by @karolba is included in updated versions of nodejs (at version 8.9.0-1) and nodejs-current (at version 9.0.0-1), so after updating with pkg up npm should work again!

lsvidal commented 6 years ago

The issue returned on nodejs-current v9.2.0

karolba commented 6 years ago

@lsvidal What package are you trying to install? I see no regression with neither lodash, express, nor server-js.

Did you by any chance happen to update npm by issuing npm install -g npm? That could break it as it would remove the patches provided by Termux.

cino893 commented 6 years ago

https://github.com/npm/npm/issues/17480#issuecomment-375908224

zawawimanja commented 6 years ago

got problem even though already try the solution above.

EACCESS: permission denied,.......

I am trying to build apps using Ionic.

zawawimanja commented 6 years ago

Thanks

On Sat, Sep 1, 2018, 12:10 AM Dimitrios Proios notifications@github.com wrote:

Worked with this:

sudo chown -R $USER:$GROUP ~/.npm

credits to: https://stackoverflow.com/questions/50639690/on-npm-install-unhandled-rejection-error-eacces-permission-denied

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/termux/termux-packages/issues/1192#issuecomment-417713103, or mute the thread https://github.com/notifications/unsubscribe-auth/AjgWu9KjH6HoaZn2DwvGCGNmXwMRJ-xoks5uWWAHgaJpZM4OrkEL .

webhacking commented 6 years ago

Give ownership to npm like this:

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
MrIceman commented 6 years ago

I solved this issue by not using npm anymore and use yarn instead

srahnama commented 5 years ago

npm i -g npm

garsharm commented 5 years ago

That seems to be an easy fix.

  1. How I end up with this error: I ran "npm install -g npm@latest". After that npm got broken.

  2. How I resolved it: remove nodejs and npm (in my case "sudo apt remove nodejs npm" worked).

  3. Install nodejs again. (in my case "sudo apt-get install nodejs"). npm is included in the package with nodejs. if you are having trouble in installing nodejs again, you can refer to https://linuxize.com/post/how-to-install-node-js-on-ubuntu-18.04/

PS: Still facing issue? if you are the only user that is accessing this project then,

you can delete the node_modules directory and install it again with npm install and that will give the node_modules the desired user permissions.

else

you have to give the required permissions to node_modules directory by sudo chown -R $USER:$GROUP ~/.npm sudo chown -R $USER:$GROUP ~/.config

Done! Thankyou

lyrathaprinces commented 5 years ago

Given permission to that folder as webhacking suggested,,, thanks man

christianrondeau commented 5 years ago

@Jean-Barbosa9 and others, I think everyone is confused here :) This is the termux packages repository, and there is no sudo nor permissions here. You probably intended to post something on the npm repository instead.

mandycui commented 5 years ago

Maybe you can try this

sudo chown -R username /home/.npm/

mohit23x commented 5 years ago

running npm cache clean worked for me!

ashraful143084 commented 5 years ago

When i upgrade nodejs in v10.16.3 and npm v6.9.0 in my ubuntu 18.04 OS. I am having this same problem. Then i give permission by running this command and solve this problem,

sudo chown -R $USER:$GROUP ~/.npm sudo chown -R $USER:$GROUP ~/.config

Done !! Thank You

christianrondeau commented 5 years ago

I think a lot of people get the repos mixed up. This is specific to Termux, Ubuntu is another story.