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

[BUG] npm doesn't work on Android #5878

Closed
2 tasks done
licy183 opened this issue Nov 21, 2022 · 7 comments
Closed
2 tasks done

[BUG] npm doesn't work on Android #5878

licy183 opened this issue Nov 21, 2022 · 7 comments
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 9.x work is associated with a specific npm 9 release

Comments

@licy183
Copy link

licy183 commented Nov 21, 2022

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

~ $ npm install yarn
npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/.npm/_cacache/tmp/14de33dd
npm ERR! dest /data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/d1/d2/d481d770644c0c5e31275a2b952a18da6097da58f146549fb26a5f5d8ac389ffcd10db5d924df1176590499cd2d92b5c21f948efab003774723c809d2d6c
npm ERR! errno EACCES
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 10427:10427 "/data/data/com.termux/files/home/.npm"

npm ERR! A complete log of this run can be found in:
npm ERR! /data/data/com.termux/files/home/.npm/_logs/2022-11-21T01_31_59_253Z-debug-0.log

Expected Behavior

NPM should install package successfully.

Steps To Reproduce

In Termux, run

apt update && apt upgrade 
apt install nodejs-lts
npm install -g npm@9.1.2
npm install yarn

Then error message will occur.

Environment

  • npm: 9.1.2
  • Node.js: 16.18.1
  • OS Name: Android 12 (Termux 0.118)
  • System Model Name: Xiaomi MIX4 (2106118C)
  • npm config:
; "user" config from /data/data/com.termux/files/home/.npmrc

foreground-scripts = true

; node bin location = /data/data/com.termux/files/usr/bin/node
; node version = v16.18.1
; npm local prefix = /data/data/com.termux/files/home
; npm version = 9.1.2
; cwd = /data/data/com.termux/files/home
; HOME = /data/data/com.termux/files/home
; Run `npm config ls -l` to show all defaults.

Additional Infomation

I've reported it in npm/cacache#155.

fs.link will try to use hard link, which is disallowed by seccomp in Android. The maintainer of termux packages have applied a patch to solve this, but when users update cacache or npm, the patch will not work anymore.

Related issues: termux/termux-packages#11293, termux/termux-packages#13293
Possible patch: https://github.com/termux/termux-packages/blob/master/packages/nodejs/deps-npm-node_modules-cacache-lib-util-move-file.js.patch

@licy183 licy183 added Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release labels Nov 21, 2022
@licy183 licy183 changed the title [BUG] <title> [BUG] npm doesn't work on Android Nov 21, 2022
@fritzy fritzy added Priority 1 high priority issue and removed Needs Triage needs review for next steps labels Nov 23, 2022
@papb
Copy link

papb commented Nov 24, 2022

npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 10427:10427 "/data/data/com.termux/files/home/.npm"

Did you try this?

@licy183
Copy link
Author

licy183 commented Nov 24, 2022

npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 10427:10427 "/data/data/com.termux/files/home/.npm"

Did you try this?

sudo means that your Android device must be rooted, but my device (and most of the devices) doen't. Hard link is disabled by seccomp on Android and only root user can create it.

@nlf
Copy link
Contributor

nlf commented Jan 4, 2023

npm@9 no longer attempts to modify file ownership. that change should resolve this issue for you. please feel free to reopen this issue, ideally with reproduction steps, if you're still experiencing this problem after updating to the latest npm@9.

@nlf nlf closed this as completed Jan 4, 2023
@licy183
Copy link
Author

licy183 commented Jan 6, 2023

Sorry for the late reply. But it seems that this issue still exists in npm@9.2.0.

asciicast

@papb
Copy link

papb commented Jan 9, 2023

I have the same problem shown by @licy183. After installing Node, we get npm v8, and after upgrading to v9, it is too late, the damage has already been done in the cache folder. Note: I am using Termux and used pkg install nodejs instead of apt install nodejs.

@ljharb
Copy link
Collaborator

ljharb commented Jan 9, 2023

@papb have you tried installing node using the only official mechanism, a download off of nodejs.org?

@licy183
Copy link
Author

licy183 commented Jan 9, 2023

@papb have you tried installing node using the only official mechanism, a download off of nodejs.org?

I don't think it is possible without proot. Termux is an Linux emulator on Android, and the libc library that all its packages are linked against is Bionic libc, the same as Android's libc. The official build of node is linked against glibc. Glibc and bionic libc are totally different implementations of the C runtime library.

Actually, this is a bug of cacache which I've reported in npm/cacache#155. moveFile function tries to use link (hard link), but hard link is blocked by seccomp on Android and it will set EPERM, and then this error will be thrown. To fix it, a check should be added at the start of this function. Just like

 async function moveFile (src, dest) {
   const isWindows = process.platform === 'win32'
+  const isAndroid = process.platform === 'android'
+
+  if (isAndroid) {
+    return move(src, dest)
+  }

   // This isn't quite an fs.rename -- the assumption is that
   // if `dest` already exists, and we get certain errors while
   // trying to move it, we should just not bother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 9.x work is associated with a specific npm 9 release
Projects
None yet
Development

No branches or pull requests

5 participants