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 incorrectly assumes existence of root-owned files on Termux #5114

Closed
2 tasks done
VoltrexKeyva opened this issue Jul 1, 2022 · 33 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@VoltrexKeyva
Copy link

VoltrexKeyva commented Jul 1, 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

On Termux, npm seems to incorrectly assume the existence of files owned by root in the .npm directory when trying to either check the outdated global packages, installing a package, or updating a package; nothing in Termux is root-owned by default (and your device must be rooted to even have anything owned by root).

This behavior has started occurring since npm v8.12.0.

Example:

$ npm outdated -g
npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/.npm/_cacache/tmp/ca13ccc3
npm ERR! dest /data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/43/a6/c7e13485e371db122c19f97a126c3d3a05e3f3050a79998bac598ab110422ff6ca2d65f0907caa47c66eb551785374e9216de04eae820a0f45c2c0cdd376
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 10272:10272 "/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-07-01T02_47_45_988Z-debug-0.log

As mentioned, this can also occur when trying to install or update a package (doesn't matter if it's global or local).

Some others seems to be experiencing the same issue: #5025, and #4451 (comment)

Expected Behavior

The expected behavior is for npm to work without assuming the existence of root-owned files that doesn't actually exist, basically to not throw the aforementioned error when checking for outdated global packages, installing/updating global or local packages.

Example:

$ npm outdated -g
Package   Current  Wanted  Latest  Location               Depended by
corepack   0.10.0  0.11.2  0.11.2  node_modules/corepack  global

Steps To Reproduce

  1. Download, install, and launch Termux from it's official website.
  2. Update all installed packages by running apt update && apt upgrade -y.
  3. Install the latest Node.js LTS release (it doesn't have to be LTS, but for the sake of the example) which bundles npm as well by running apt install nodejs-lts -y.
  4. Update npm to v8.12.0 or higher by running npm i -g npm.
  5. Now try to install/update the global packages, it can also be local packages; for this step, try running npm update -g, and you'll encounter this error (some details may differ depending on your environment, but it's the same error):
npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/.npm/_cacache/tmp/ca13ccc3
npm ERR! dest /data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/43/a6/c7e13485e371db122c19f97a126c3d3a05e3f3050a79998bac598ab110422ff6ca2d65f0907caa47c66eb551785374e9216de04eae820a0f45c2c0cdd376
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 10272:10272 "/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-07-01T02_47_45_988Z-debug-0.log

Environment

  • npm: v8.13.2
  • Node.js: v16.15.1
  • OS Name: Android 11
  • System Model Name: Galaxy A40 | SM-A405FN/DS
  • npm config:
; "user" config from /data/data/com.termux/files/home/.npmrc

//registry.npmjs.org/:_authToken = (protected)
foreground-scripts = true

; node bin location = /data/data/com.termux/files/usr/bin/node
; node version = v16.15.1
; npm local prefix = /data/data/com.termux/files/home
; npm version = 8.13.2
; cwd = /data/data/com.termux/files/home
; HOME = /data/data/com.termux/files/home
; Run `npm config ls -l` to show all defaults.
@VoltrexKeyva VoltrexKeyva added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Jul 1, 2022
@VoltrexKeyva VoltrexKeyva changed the title [BUG] npm assumes existence of root-owned files on Termux [BUG] npm incorrectly assumes existence of root-owned files on Termux Jul 1, 2022
@Haiz14
Copy link

Haiz14 commented Jul 9, 2022

I am having the same error prompt when i do npm install nodemon on termux

@azurenekowo
Copy link

Same! I thought I'm the only one having this issue.

I have a Samsung A50S, npm v8.13.2, v18.4.0, also using Termux.

npm ERR! code EACCES
npm ERR! syscall link                                             npm ERR! path /data/data/com.termux/files/home/.npm/_cacache/tmp/d728ef7a                                                           npm ERR! dest /data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/76/f3/b9339dafee6ec3cbdebe5d49f35cdb10ff49e9b18a54e9d2f6d39900b440ee7acc28cf7694ddb87550ca0ae1c426706b41d584722caaa9f835e2d3997316
npm ERR! errno -13                                                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 10455:10455 "/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-07-11T16_22_26_481Z-debug-0.log

@azurenekowo
Copy link

Ok so after doing

$ pkg uninstall nodejs

And run

$ pkg install nodejs-lts

It worked fine. No idea how.

@VoltrexKeyva
Copy link
Author

It worked fine. No idea how.

That's because reinstalling Node.js replaces the currently installed npm with the one shipped with that Node.js binary, as of writing this, the current Node.js LTS release from the Termux repositories ship npm v18.11.x which this issue isn't present in.

As mentioned, this issue has been occurring since v8.12.0.

@nlf
Copy link
Contributor

nlf commented Jul 13, 2022

this actually has nothing to do with root ownership, the error messaging there is not great. any EACCES or EPERM error relating to your cache directory triggers this exact warning.

do you have write access to the cache directory? what filesystem is it? can one of you seeing this problem post the full debug log here?

@VoltrexKeyva
Copy link
Author

VoltrexKeyva commented Jul 13, 2022

this actually has nothing to do with root ownership, the error messaging there is not great. any EACCES or EPERM error relating to your cache directory triggers this exact warning.

do you have write access to the cache directory? what filesystem is it? can one of you seeing this problem post the full debug log here?

In my case I have full write access to the npm cache directory, if I didn't then any npm version older than 8.12.0 would've also failed with the same error, which they don't.

I don't think the type of file system is relevant here but my device's file system type is ext4.

The debug log:

$ npm update -g --verbose
Debug log
npm verb cli /data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/usr/bin/npm
npm info using npm@8.13.2
npm info using node@v16.15.1
npm timing npm:load:whichnode Completed in 2ms
npm timing config:load:defaults Completed in 11ms
npm timing config:load:file:/data/data/com.termux/files/usr/lib/node_modules/npm/npmrc Completed in 27ms
npm timing config:load:builtin Completed in 28ms
npm timing config:load:cli Completed in 16ms
npm timing config:load:env Completed in 3ms
npm timing config:load:project Completed in 21ms
npm timing config:load:file:/data/data/com.termux/files/home/.npmrc Completed in 7ms
npm timing config:load:user Completed in 9ms
npm timing config:load:file:/data/data/com.termux/files/usr/etc/npmrc Completed in 1ms
npm timing config:load:global Completed in 1ms
npm timing config:load:validate Completed in 1ms
npm timing config:load:credentials Completed in 5ms
npm timing config:load:setEnvs Completed in 6ms
npm timing config:load Completed in 107ms
npm timing npm:load:configload Completed in 109ms
npm timing npm:load:mkdirpcache Completed in 5ms
npm timing npm:load:mkdirplogs Completed in 3ms
npm verb title npm update
npm verb argv "update" "--global" "--loglevel" "verbose"
npm timing npm:load:setTitle Completed in 7ms
npm timing config:load:flatten Completed in 17ms
npm timing npm:load:display Completed in 45ms
npm verb logfile logs-max:10 dir:/data/data/com.termux/files/home/.npm/_logs
npm verb logfile /data/data/com.termux/files/home/.npm/_logs/2022-07-13T23_20_12_621Z-debug-0.log
npm timing npm:load:logFile Completed in 33ms
npm timing npm:load:timers Completed in 0ms
npm timing npm:load:configScope Completed in 1ms
npm timing npm:load Completed in 214ms
npm timing arborist:ctor Completed in 4ms
npm timing idealTree:init Completed in 30ms
npm timing idealTree:userRequests Completed in 14ms
npm http fetch GET 200 https://registry.npmjs.org/corepack 1535ms (cache updated)
npm http fetch GET 200 https://registry.npmjs.org/npm 1504ms (cache updated)
npm timing idealTree:#root Completed in 3116ms
npm timing idealTree:node_modules/corepack Completed in 0ms
npm timing idealTree:node_modules/npm Completed in 0ms
npm timing idealTree:buildDeps Completed in 3124ms
npm timing idealTree:fixDepFlags Completed in 4ms
npm timing idealTree Completed in 3184ms
npm timing command:update Completed in 3245ms
npm verb type system
npm verb stack FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/corepack: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/ecbbb0fd' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/8b/29/d8d04509b38b390ebcba4956b8fb2955f88570f48241edffb01128b2dcdfb4580c453db04a422a8046fb9fdf7c7c9c31a25a64ac280c8f7892511b0798a7'
npm verb stack     at /data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/minipass-fetch/lib/body.js:168:15
npm verb stack     at async RegistryFetcher.packument (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:99:25)
npm verb stack     at async RegistryFetcher.manifest (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:124:23)
npm verb stack     at async Arborist.[nodeFromEdge] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1108:19)
npm verb stack     at async Arborist.[buildDepStep] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:976:11)
npm verb stack     at async Arborist.buildIdealTree (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:218:7)
npm verb stack     at async Arborist.reify (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:153:5)
npm verb stack     at async Update.exec (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/commands/update.js:65:5)
npm verb stack     at async module.exports (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/cli.js:78:5)
npm verb cwd /data/data/com.termux/files/home
npm verb Linux 4.4.177-24085844
npm verb node v16.15.1
npm verb npm  v8.13.2
npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/.npm/_cacache/tmp/ecbbb0fd
npm ERR! dest /data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/8b/29/d8d04509b38b390ebcba4956b8fb2955f88570f48241edffb01128b2dcdfb4580c453db04a422a8046fb9fdf7c7c9c31a25a64ac280c8f7892511b0798a7
npm ERR! errno EACCES
npm verb FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/corepack: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/ecbbb0fd' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/8b/29/d8d04509b38b390ebcba4956b8fb2955f88570f48241edffb01128b2dcdfb4580c453db04a422a8046fb9fdf7c7c9c31a25a64ac280c8f7892511b0798a7'
    at /data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/minipass-fetch/lib/body.js:168:15
    at async RegistryFetcher.packument (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:99:25)
    at async RegistryFetcher.manifest (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:124:23)
    at async Arborist.[nodeFromEdge] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1108:19)
    at async Arborist.[buildDepStep] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:976:11)
    at async Arborist.buildIdealTree (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:218:7)
    at async Arborist.reify (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:153:5)
    at async Update.exec (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/commands/update.js:65:5)
    at async module.exports (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/cli.js:78:5)
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 10272:10272 "/data/data/com.termux/files/home/.npm"
npm verb exit 1
npm timing npm Completed in 3842ms
npm verb unfinished npm timer reify 1657754413199
npm verb unfinished npm timer reify:loadTrees 1657754413245
npm verb code 1

npm ERR! A complete log of this run can be found in:
npm ERR!     /data/data/com.termux/files/home/.npm/_logs/2022-07-13T23_20_12_621Z-debug-0.log
Debug log for the newer npm v8.15.0 release
npm verb cli /data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/usr/bin/npm
npm info using npm@8.15.0
npm info using node@v16.15.1
npm timing npm:load:whichnode Completed in 1ms
npm timing config:load:defaults Completed in 9ms
npm timing config:load:file:/data/data/com.termux/files/usr/lib/node_modules/npm/npmrc Completed in 13ms
npm timing config:load:builtin Completed in 14ms
npm timing config:load:cli Completed in 13ms
npm timing config:load:env Completed in 2ms
npm timing config:load:project Completed in 11ms
npm timing config:load:file:/data/data/com.termux/files/home/.npmrc Completed in 9ms
npm timing config:load:user Completed in 9ms
npm timing config:load:file:/data/data/com.termux/files/usr/etc/npmrc Completed in 9ms
npm timing config:load:global Completed in 10ms
npm timing config:load:validate Completed in 1ms
npm timing config:load:credentials Completed in 6ms
npm timing config:load:setEnvs Completed in 5ms
npm timing config:load Completed in 85ms
npm timing npm:load:configload Completed in 86ms
npm timing npm:load:mkdirpcache Completed in 5ms
npm timing npm:load:mkdirplogs Completed in 1ms
npm verb title npm update
npm verb argv "update" "--global" "--loglevel" "verbose"
npm timing npm:load:setTitle Completed in 6ms
npm timing config:load:flatten Completed in 16ms
npm timing npm:load:display Completed in 42ms
npm verb logfile logs-max:10 dir:/data/data/com.termux/files/home/.npm/_logs
npm verb logfile /data/data/com.termux/files/home/.npm/_logs/2022-07-21T13_52_24_138Z-debug-0.log
npm timing npm:load:logFile Completed in 32ms
npm timing npm:load:timers Completed in 1ms
npm timing npm:load:configScope Completed in 1ms
npm timing npm:load Completed in 183ms
npm timing arborist:ctor Completed in 6ms
npm timing idealTree:init Completed in 34ms
npm timing idealTree:userRequests Completed in 16ms
npm http fetch GET 200 https://registry.npmjs.org/corepack 1853ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/npm 1921ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/prettier 685ms (cache miss)
npm timing idealTree:#root Completed in 4593ms
npm timing idealTree:node_modules/corepack Completed in 0ms
npm timing idealTree:node_modules/npm Completed in 0ms
npm timing idealTree:node_modules/prettier Completed in 0ms
npm timing idealTree:buildDeps Completed in 4606ms
npm timing idealTree:fixDepFlags Completed in 7ms
npm timing idealTree Completed in 4673ms
npm timing command:update Completed in 4771ms
npm verb type system
npm verb stack FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/corepack: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/9b99c620' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/8b/29/d8d04509b38b390ebcba4956b8fb2955f88570f48241edffb01128b2dcdfb4580c453db04a422a8046fb9fdf7c7c9c31a25a64ac280c8f7892511b0798a7'
npm verb stack     at /data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/minipass-fetch/lib/body.js:168:15
npm verb stack     at async RegistryFetcher.packument (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:99:25)
npm verb stack     at async RegistryFetcher.manifest (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:124:23)
npm verb stack     at async Arborist.[nodeFromEdge] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1108:19)
npm verb stack     at async Arborist.[buildDepStep] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:976:11)
npm verb stack     at async Arborist.buildIdealTree (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:218:7)
npm verb stack     at async Arborist.reify (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:154:5)
npm verb stack     at async Update.exec (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/commands/update.js:65:5)
npm verb stack     at async module.exports (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/cli.js:78:5)
npm verb cwd /data/data/com.termux/files/home
npm verb Linux 4.4.177-24392161
npm verb node v16.15.1
npm verb npm  v8.15.0
npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/.npm/_cacache/tmp/9b99c620
npm ERR! dest /data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/8b/29/d8d04509b38b390ebcba4956b8fb2955f88570f48241edffb01128b2dcdfb4580c453db04a422a8046fb9fdf7c7c9c31a25a64ac280c8f7892511b0798a7
npm ERR! errno EACCES
npm verb FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/corepack: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/9b99c620' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/8b/29/d8d04509b38b390ebcba4956b8fb2955f88570f48241edffb01128b2dcdfb4580c453db04a422a8046fb9fdf7c7c9c31a25a64ac280c8f7892511b0798a7'
    at /data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/minipass-fetch/lib/body.js:168:15
    at async RegistryFetcher.packument (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:99:25)
    at async RegistryFetcher.manifest (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/pacote/lib/registry.js:124:23)
    at async Arborist.[nodeFromEdge] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1108:19)
    at async Arborist.[buildDepStep] (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:976:11)
    at async Arborist.buildIdealTree (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:218:7)
    at async Arborist.reify (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:154:5)
    at async Update.exec (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/commands/update.js:65:5)
    at async module.exports (/data/data/com.termux/files/usr/lib/node_modules/npm/lib/cli.js:78:5)
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 10272:10272 "/data/data/com.termux/files/home/.npm"
npm verb exit 1
npm timing npm Completed in 5446ms
npm verb unfinished npm timer reify 1658411544793
npm verb unfinished npm timer reify:loadTrees 1658411544869
npm verb code 1

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

@VoltrexKeyva
Copy link
Author

@nlf any updates on this?

@Haiz14
Copy link

Haiz14 commented Jul 26, 2022

@VoltrexMaster just doing pkg uninstall node works for me

@VoltrexKeyva
Copy link
Author

VoltrexKeyva commented Jul 26, 2022

@VoltrexMaster just doing pkg uninstall node works for me

This is not an actual fix for the issue at hand, doing that just uninstalls Node.js, and reinstalling Node.js will install an older version of npm (v8.11.x) where this issue is not present.

The error I've denoted in my issue started occuring since npm v8.12.x which is still not fixed even in npm v8.15.x.

@GameratorCreator
Copy link

GameratorCreator commented Jul 27, 2022

The solution that worked for me was to set the cache location for npm like so: npm config set cache /path-to-tmp --global
npm is trying to use a cache location that does not exist or it has no access to.

@VoltrexKeyva
Copy link
Author

VoltrexKeyva commented Jul 27, 2022

The solution that worked for me was to set the cache location for npm like so: npm config set cache /path-to-tmp --global
npm is trying to use a cache location that does not exist or it has no access to.

In this case, npm does have full access to the default cache directory which is located in ~/.npm, any npm version equal to or older than v8.11.x works just fine, but any npm version equal to or higher than v8.12.x does not, this is an issue with npm itself, not Termux nor the file system, or the cache directory.

I suspect there is an issue with Arborist which causes this issue, although I'm not familiar with it's codebase so I'm unsure what exactly causes this issue.

@KAZI-SAMIR
Copy link

any update on it,

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 10113:10113 "/data/data/com.termux/files/home/.npm/_cached/tmp"

@ghost
Copy link

ghost commented Aug 13, 2022

Do somebody have the idea of solving this...permanently?

$ npm i puppeteer

npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/scraper/_cacache/tmp/8666b45d
npm ERR! dest /data/data/com.termux/files/home/scraper/_cacache/content-v2/sha512/dd/ca/33c2c08dcefe2ed686a4b3e2ef3b99971397f94486093eafcb501f059de027569c9a37a6eb68f474ccd8154363fa39af38c7a7d94bc8b8cac211399754c3
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 10673:10673 "/data/data/com.termux/files/home/scraper"

npm ERR! A complete log of this run can be found in:
npm ERR!     /data/data/com.termux/files/home/scraper/_logs/2022-08-13T12_23_20_406Z-debug-0.log

@ghost
Copy link

ghost commented Aug 13, 2022

Do somebody have the idea of solving this...permanently?

$ npm i puppeteer

npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/scraper/_cacache/tmp/8666b45d
npm ERR! dest /data/data/com.termux/files/home/scraper/_cacache/content-v2/sha512/dd/ca/33c2c08dcefe2ed686a4b3e2ef3b99971397f94486093eafcb501f059de027569c9a37a6eb68f474ccd8154363fa39af38c7a7d94bc8b8cac211399754c3
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 10673:10673 "/data/data/com.termux/files/home/scraper"

npm ERR! A complete log of this run can be found in:
npm ERR!     /data/data/com.termux/files/home/scraper/_logs/2022-08-13T12_23_20_406Z-debug-0.log

This is shown with npm v8.17.0

@griffi-gh
Copy link

griffi-gh commented Aug 22, 2022

same issue, i can't even downgrade
nvm latest lts release uses the right version of npm

@Haiz14
Copy link

Haiz14 commented Aug 22, 2022

@griffi-gh did u do pkg uninstall node ?

@griffi-gh
Copy link

griffi-gh commented Aug 22, 2022

@griffi-gh did u do pkg uninstall node ?

yep, node reinstall downgrades npm.
But downgrade is never the solution, just a temporary workaround.

@Haiz14
Copy link

Haiz14 commented Aug 22, 2022

@griffi-gh happy debugging then ;)

@porkus1990
Copy link

any update on this? still facing this issue

@joshcangit
Copy link

joshcangit commented Oct 12, 2022

Yes, this is still an issue.

npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/mathjs reason: Invalid response body while trying to fetch https://registry.npmjs.org/mathjs: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/6c8e0ad5' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/78/9f/99ba86dc6a017a9697bef8f0545dd6ab3f5cf68a52be39f96ed49947ae33d6dbce8a68276ac1af10603581be09a5679d3b2bce52861216f3b817ef030046'

npm ERR! A complete log of this run can be found in:
npm ERR!     /data/data/com.termux/files/home/.npm/_logs/2022-10-12T04_00_53_203Z-debug-0.log
All packages are up to date.

It seems npm can check for updates to packages but the issue is maybe when writing it to cache, it gets a permission denied error.
I kind of avoided the issue by reinstalling nodejs on Termux.
Then, making sure to never install npm using npm.

@porkus1990
Copy link

porkus1990 commented Oct 12, 2022

for github-actions, i worked around this issue by
rm -rf ./.npm-cache || true # just to be sure
mkdir -p ./.npm-cache || true # just to be sure
npm cache clean -f
export npm_config_cache=./.npm-cache

but it's still annoying and not a pretty solution..

@anikdife
Copy link

anikdife commented Nov 2, 2022

This can't be solved by any of the ways formulated above. Only solution I have found is just by avoiding it by changing npm version. Current release of npm is 9.0.1. Follow the commands
sudo npm i -g npm@9.0.1
sudo npm i -g npx --force
sudo npx create-react-app app-name
I hope it will work, as it did in my case.

@Haiz14
Copy link

Haiz14 commented Nov 2, 2022

I aint facing this problem anymore. I just did normal installation using pkg i nodejs and it's working fine.

u0_a260@localhost ~ (main) [1]> npm outdated -g
Package                       Current  Wanted  Latest  Location                                   Depended by
@tailwindcss/language-server    0.0.9  0.0.10  0.0.10  node_modules/@tailwindcss/language-server  global
corepack                       0.14.1  0.15.0  0.15.0  node_modules/corepack                      global
u0_a260@localhost ~ (main) [1]>

@VoltrexKeyva
Copy link
Author

This issue no longer occurs after the Node.js runtime was updated to v16.18.0 in the Termux repositories, closing.

@joshcangit
Copy link

Nope, still is an issue for me.

npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/corepack reason: Invalid response body while trying to fetch https://registry.npmjs.org/corepack: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/c61e9024' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/52/2a/0b70eea08530f14d9f838b351a93d56ca373712ba0fb33ceee303a387ce151e3c7d00f0e0e241d81ef4eb37cbdaa3e0850434bd7aa1452a8cccba61b9ab5'

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

@griffi-gh
Copy link

Nope, still is an issue for me.

npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/corepack reason: Invalid response body while trying to fetch https://registry.npmjs.org/corepack: EACCES: permission denied, link '/data/data/com.termux/files/home/.npm/_cacache/tmp/c61e9024' -> '/data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/52/2a/0b70eea08530f14d9f838b351a93d56ca373712ba0fb33ceee303a387ce151e3c7d00f0e0e241d81ef4eb37cbdaa3e0850434bd7aa1452a8cccba61b9ab5'

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

It's another issue

@griffi-gh
Copy link

Similar but yes it is different.

  1. It's not similar at all
  2. try --no-bin-links

@weasam
Copy link

weasam commented Nov 16, 2022

root@host:/var/www/mycloud.com/apps/recognize# sudo -u www-data make
rm -rf js
rm -rf /var/www/mycloud.com/apps/recognize/build/artifacts/sign
rm -rf node_modules
npm ci
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /var/www/.npm
npm ERR! errno -13
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 33:33 "/var/www/.npm"

npm ERR! Log files were not written due to an error writing to the directory: /var/www/.npm/_logs
npm ERR! You can rerun the command with --loglevel=verbose to see the logs in your terminal
make: *** [Makefile:20: npm-init] Error 243

--------------------------------------------I fixed it -------------------------------------------------------
sudo mkdir /var/www/.npm
sudo chown -R 33:33 "/var/www/.npm"

@guritso
Copy link

guritso commented Nov 19, 2022

This is now happening on the 9.1.2 version:

npm ERR! code EACCES
npm ERR! syscall link
npm ERR! path /data/data/com.termux/files/home/.npm/_cacache/tmp/4f642a1f
npm ERR! dest /data/data/com.termux/files/home/.npm/_cacache/content-v2/sha512/be/ab/0cbc90e0f25082fb10a4b6cbae24791280fb9c61657faeea92f50ace86a920874b1dc0377c202e3e1b25d5067bbb2f526e14d1d0e5c7aa146dbbcb0ed718
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 10413:10413 "/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-19T20_47_59_413Z-debug-0.log

Can't solve with sudo since I don't have root

@zstauber-NMENV
Copy link

November 29th, installing Termux on a new device and was introduced to this thread. Still a problem. I tried the solution above of changing the /tmp directory from GamerCreator, and it just decided to balk about the new directory still.
Node v18.12.1
NPM v9.1.2

@guritso
Copy link

guritso commented Nov 30, 2022

November 29th, installing Termux on a new device and was introduced to this thread. Still a problem. I tried the solution above of changing the /tmp directory from GamerCreator, and it just decided to balk about the new directory still.
Node v18.12.1
NPM v9.1.2

Most up-to-date information we have about this: termux/termux-packages#13293

sharmaaayush-OH added a commit to scheduleonce/once-ui that referenced this issue Feb 9, 2023
@EhabBen10
Copy link

EhabBen10 commented Mar 12, 2023

I had the same problem on my Mac when trying to create an Angular project using the command
'npm init @angular myApp'.
To solve the issue, I tried running the command with 'sudo' in front of it, like this:
'sudo npm init @angular myApp'.
This worked for me!

sharmaaayush-OH added a commit to scheduleonce/once-ui that referenced this issue Mar 16, 2023
guru-aot added a commit to bcgov/SIMS that referenced this issue Dec 12, 2023
Note: The branch name is created without a # in the front, to test my
build and deployments from my local.

- [x] Investigate the issue and apply the fix on all our custom
Dockerfile (Api, web, workers, queue-consumers, load-test-gateway &
db-migration)
- [x] Most updated image in node has to be deployed


What does EACCES error means in node -
https://betterstack.com/community/guides/scaling-nodejs/nodejs-errors/#13-eacces

On Analysing the issue, i was able to understand that this issue happens
in certain version of node & npm libraries, some related bugs reported
in the years are given below for reference.
- npm/cli#5114
- https://stackoverflow.com/questions/71450392/npm-cache-issue
-
https://stackoverflow.com/questions/67163194/jenkins-build-issue-npm-err-your-cache-folder-contains-root-owned-files

The possible solutions given by the people are alwauys these 2
- give sudo permission and access for the user 1001 for the /.npm
directory/ - which is not always right to have a sudo persmission for a
user in dockerfile
- upgrade the node version as it states to a newer version that this
issue is not happening - going with this route as we have a newer
version of redhat that contains the new version from the one deplyoed
already with some security issues.


https://catalog.redhat.com/software/containers/ubi8/nodejs-18/6278e5c078709f5277f26998?architecture=amd64&image=65302e01ec5935b621691d22&container-tabs=packages

![image](https://github.com/bcgov/SIMS/assets/62901416/1f7136b4-3daf-43d3-9af3-6232865be1e3)


https://catalog.redhat.com/software/containers/ubi8/nodejs-18/6278e5c078709f5277f26998?architecture=amd64&image=6543c3d67371c4bd3014291a&container-tabs=packages
<img width="1290" alt="image"
src="https://github.com/bcgov/SIMS/assets/62901416/a492658d-bd7f-4a92-9513-2b26038a475c">

Analyzing the changelogs of npm js, there has been bugs related to cache
that has been fixed.
https://docs.npmjs.com/cli/v9/using-npm/changelog#981-2023-07-18
https://docs.npmjs.com/cli/v9/using-npm/changelog#967-2023-05-17


![image](https://github.com/bcgov/SIMS/assets/62901416/e35782a3-28f3-4c5c-982b-58b06ac6404b)
npm/cli#6464
The bug reported may not state the same issue we are facing but its
related to the cache error that is happening in the version we were
using.

So updating the redhat image to the latest version is what was taken as
an action to solve this issue.

Note:
https://app.zenhub.com/workspaces/student-information-management-system-5fce9df5aa1b45000e937014/issues/gh/bcgov/sims/2453
is also done as part of this PR.
- [x] Remove variables from Makefile
- [x] Remove references from docker-build.yml


As suggested by @andrewsignori-aot
#2577 (comment) changed
the permission of users in the group 0 for the folder ./.npm to have
write access

Container before assigning the write permission
<img width="889" alt="image"
src="https://github.com/bcgov/SIMS/assets/62901416/a8d95861-d538-4661-9e6c-429b30f2f6e3">

Container after assigning the write permission
<img width="740" alt="image"
src="https://github.com/bcgov/SIMS/assets/62901416/2343b44b-2b4b-4849-8f55-084beea91d0b">


Addded only the permissions for the ./.npm folder as in the past month
the failed logs show this error happening only in the ./.npm folder.

https://kibana-openshift-logging.apps.silver.devops.gov.bc.ca/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-30d,mode:quick,to:now))&_a=(columns:!(message),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'8841c680-a15b-11eb-a4dc-e5bf19f04239',key:kubernetes.namespace_name,negate:!f,params:(query:'0c27fb-test',type:phrase),type:phrase,value:'0c27fb-test'),query:(match:(kubernetes.namespace_name:(query:'0c27fb-test',type:phrase))))),index:'8841c680-a15b-11eb-a4dc-e5bf19f04239',interval:auto,query:(language:lucene,query:'%22sudo%20chown%20-R%20%22'),sort:!('@timestamp',desc))

<img width="923" alt="image"
src="https://github.com/bcgov/SIMS/assets/62901416/ba796f55-5447-4c4a-9fef-aba1ab129d5c">
@kavana-14
Copy link

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno -13
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 1007390000:0 "/.npm"

npm ERR! Log files were not written due to an error writing to the directory: /.npm/_logs
npm ERR! You can rerun the command with --loglevel=verbose to see the logs in your terminal

I'm creating a react app on openshift, but after deployment of pod when i "rsh" into container shell and try to run "npm start" i'm getting above error.

$ ls -l /.npm
ls: cannot access '/.npm': No such file or directory
$ ls -l ~/.npm
ls: cannot access '//.npm': No such file or directory
$ oc rsh client-56975c6c4-x454j
$ npm config get cache
/.npm
how to solve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests