termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

Error on the new version of NPM

Open guritso opened this issue 2 years ago • 24 comments

I'm getting this error on the version 9.1.2 of npm:

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

As I don't have root , I can't solve it with what is indicated in the log

This happens with anything I try, like

npm install package
npm install -g npm

guritso avatar Nov 19 '22 21:11 guritso

It tries to make a hardlink, which is not allowed on android. Same issue as in https://github.com/termux/termux-packages/issues/11293, where npm install -g package worked as a work around

Grimler91 avatar Nov 19 '22 21:11 Grimler91

I think we should patch this, if this version of npm is what we provide

truboxl avatar Nov 20 '22 01:11 truboxl

Maybe we should report this issue to https://github.com/npm/cacache? We have patched it using https://github.com/termux/termux-packages/blob/master/packages/nodejs/deps-npm-node_modules-cacache-lib-util-move-file.js.patch, but if user tries to update npm or cacache, the patch will not work.

licy183 avatar Nov 20 '22 05:11 licy183

@GuriZenit, we are talking about native Termux environment and not proot based distributions (including third party ones).

thunder-coding avatar Nov 24 '22 01:11 thunder-coding

We really need a gimmick that forbids users' updating npm, if the patch is not likely to be merged upstream. Could be just a matter of documentation though.

xtkoba avatar Dec 15 '22 07:12 xtkoba

Yeah sure @xtkoba, we can add a notice to the npm's global install script when installing npm. Just wait for some time though. My main device is for repair so I can't test the binaries built by CI. Once it comes, will look into it

thunder-coding avatar Dec 16 '22 01:12 thunder-coding

It seems that [email protected] has fixed this.

licy183 avatar Jan 06 '23 16:01 licy183

It seems that [email protected] has fixed this.

Still have the error, both now and when testing in v9.2.0 release. does it work for you?

guritso avatar Jan 06 '23 16:01 guritso

Emmm... It seems to work on Bluestacks, but not on my real device. I will record it and report upstream.

licy183 avatar Jan 06 '23 16:01 licy183

It seems that [email protected] has fixed this.

Still have the error, both now and when testing in v9.2.0 release. does it work for you?

Same here :/

ginger-tek avatar Jan 09 '23 00:01 ginger-tek

Use yarn to install npm packages !

OurCodeBase avatar Jan 14 '23 19:01 OurCodeBase

Just pushed 6b05a8e7ba0435bec9afccd6e809329a7a62c27d. Will now include an error message when trying to install npm globally. Also using --force will allow to install it anyway (provided for people who know what they are doing)

thunder-coding avatar Jan 17 '23 13:01 thunder-coding

So, uh, any other way to upgrade npm?

elenakrittik avatar Feb 12 '23 22:02 elenakrittik

Error;-;

ERR! Can't install npm globally as it will very likely break installation of global packages using npm. See https://github.com/termux/termux-packages/issues/13293

npm ERR! A complete log of this run can be found in: npm ERR! /data/data/com.termux/files/home/.npm/_logs/2023-03-12T00_03_10_133Z-debug-0.log

Alex1Sturm avatar Mar 12 '23 00:03 Alex1Sturm

So, uh, any other way to upgrade npm?

@ItsAleph I think I may have found a way!

Ironically, the suggestion by @OurCodeBase works perfectly for this: using yarn. Even though I've been getting the same errors as everyone else, this did the trick:

npm i -g yarn (if not already installed) yarn global add npm

Oh my machine, this runs without errors. After installation, npm -v gives the expected result. Does this work for any of you too?

marktforsyth avatar Apr 20 '23 17:04 marktforsyth

No, yarn global add npm only installed under the home directory.

But leaving the system-wide npm module alone is the only option. Overwriting it in any way will cause this issue.

If I need a more up-to-date npm, best is to get it with yarn or pnpm.

joshcangit avatar Apr 21 '23 01:04 joshcangit

Hello @joshcangit If you are facing issues with yarn then reset everything and install yarn using package manager pkg install yarn. This will install yarn, npm, and nodejs automatically. And then you can run yarn command anywhere.

OurCodeBase avatar Apr 21 '23 17:04 OurCodeBase

Hello @joshcangit If you are facing issues with yarn then reset everything and install yarn using package manager pkg install yarn. This will install yarn, npm, and nodejs automatically. And then you can run yarn command anywhere.

Um actually, the issue is with npm.

I updated it by installing under the home directory then copying it over. I don't think it matters which package manager I used to do this.

joshcangit avatar Apr 21 '23 17:04 joshcangit

Why are you using npm when yarn is much stable than it.

OurCodeBase avatar Apr 21 '23 17:04 OurCodeBase

Why are you using npm when yarn is much stable than it.

My idea is npm for system-wide packages. But yarn or pnpm for packages in current working directory.

joshcangit avatar Apr 21 '23 17:04 joshcangit

So, uh, any other way to upgrade npm?

@ItsAleph I think I may have found a way!

Ironically, the suggestion by @OurCodeBase works perfectly for this: using yarn. Even though I've been getting the same errors as everyone else, this did the trick:

npm i -g yarn (if not already installed) yarn global add npm

Oh my machine, this runs without errors. After installation, npm -v gives the expected result. Does this work for any of you too?

Works for my needs. Thanks!

Why are you using npm when yarn is much stable than it.

Woah what an opinionated comment. Not sure for you, but from my own experience, for global packages npm works better. Everyone chooses what works for them, don't bomb people with opinions unless asked :p

elenakrittik avatar Apr 22 '23 07:04 elenakrittik

Using yarn to install npm globally, initially seems to work, but upon closer examination, using a tool like npm-check-updates, reveals that it doesn't completely work as expected. ncu -g will show the old (no longer installed 9.6.3) version as installed, and the currently installed (9.6.7) as available for install. 'yarn' != 'npm', therefore, yarn is not updating the same (config?) files as npm, thus, issues remain. It's a quick and dirty workaround, which may be sufficient for some scenarios and/or people, and not sufficient for others. Nothing beats a proper fix.

Leif-W avatar May 26 '23 19:05 Leif-W

This has been fixed in https://github.com/npm/cacache/pull/195, it works now

phanirithvij avatar May 27 '23 00:05 phanirithvij

This has been fixed in npm/cacache#195, it works now

Thanks for pointing out, this issue will be closed as completed once we have upgrade to a version of nodejs which comes with this fix for npm. LTS should not be much of a problem, but the latest version will take some time to catch up

thunder-coding avatar May 27 '23 10:05 thunder-coding

You can try this: https://github.com/varxez/termux-npm-updater

varxez avatar Jul 04 '23 09:07 varxez

https://github.com/varxez/termux-npm-updater

Not sure if this works. I've tried copying npm from node_modules in the home folder. The error still occured.

joshcangit avatar Jul 04 '23 13:07 joshcangit

You can try this: https://github.com/varxez/termux-npm-updater

That script ain't going to work, you are just replacing the npm binary and the node_modules directory without actually applying the fix which we have in our packaged version of node

thunder-coding avatar Jul 04 '23 13:07 thunder-coding

You can try this: https://github.com/varxez/termux-npm-updater

That script ain't going to work, you are just replacing the npm binary and the node_modules directory without actually applying the fix which we have in our packaged version of node

Bro, how about if you personally check the functionality of the script?

varxez avatar Jul 04 '23 20:07 varxez

You can try this: https://github.com/varxez/termux-npm-updater

That script ain't going to work, you are just replacing the npm binary and the node_modules directory without actually applying the fix which we have in our packaged version of node

Bro, how about if you personally check the functionality of the script?

This script does the same job as

npm i -g npm@latest --force

guritso avatar Jul 04 '23 21:07 guritso

@varxez npm is not "node package manager" 🤦 https://github.com/npm/cli#is-npm-an-acronym-for-node-package-manager

elenakrittik avatar Jul 08 '23 09:07 elenakrittik