node-red / node-red-docker

Repository for all things Node-RED and Docker related
Apache License 2.0
481 stars 383 forks source link

Can't update/install packages - NPM permissions error #337

Closed rborkow closed 2 years ago

rborkow commented 2 years ago

What are the steps to reproduce?

  1. Create a new, empty folder on the host machine
  2. Assign the new folder to the /data folder in the docker-compose file.
  3. Confirm the new folder has the proper permissions.
  4. Destroy and re-create the node-red container.
  5. Try to install a package

What happens?

I first ran into this error when trying to update packages via the palette browser - all package updates would fail with some version of the below error (nom debug log attached):

-----------------------------------------------------------
2022-09-27T20:09:05.658Z Install : node-red-contrib-huemagic 4.2.2

2022-09-27T20:09:05.753Z npm install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --production --engine-strict node-red-contrib-huemagic@4.2.2
2022-09-27T20:09:05.925Z [err] npm
2022-09-27T20:09:05.925Z [err]  WARN config production Use `--omit=dev` instead.
2022-09-27T20:09:07.892Z [err] npm
2022-09-27T20:09:07.892Z [err]  ERR! code EPERM
2022-09-27T20:09:07.892Z [err] npm
2022-09-27T20:09:07.892Z [err]  ERR!
2022-09-27T20:09:07.892Z [err]  syscall link
2022-09-27T20:09:07.892Z [err] npm ERR!
2022-09-27T20:09:07.892Z [err]  path /data/.npm/_cacache/tmp/1a0389f8
2022-09-27T20:09:07.892Z [err] npm ERR! dest /data/.npm/_cacache/content-v2/sha512/11/36/43428af2c6e38573d8b54e24dc87ca1497a3ecc045340f770ac1278ccefd6c69591bc5df7bbe04190edd39209b36e7cce0ca16f417fd366502b6c5bcdeca
2022-09-27T20:09:07.892Z [err] npm ERR! errno
2022-09-27T20:09:07.892Z [err]  EPERM
2022-09-27T20:09:07.894Z [err] npm ERR! 
2022-09-27T20:09:07.894Z [err] npm ERR! Your cache folder contains root-owned files, due to a bug in
2022-09-27T20:09:07.894Z [err] npm ERR! previous versions of npm which has since been addressed.
2022-09-27T20:09:07.894Z [err] npm 
2022-09-27T20:09:07.894Z [err] ERR! 
2022-09-27T20:09:07.894Z [err] npm ERR! To permanently fix this problem, please run:
2022-09-27T20:09:07.894Z [err] npm ERR!   sudo chown -R 1000:1000 "/data/.npm"
2022-09-27T20:09:07.895Z [err] 
2022-09-27T20:09:07.895Z [err] npm ERR! A complete log of this run can be found in:
2022-09-27T20:09:07.895Z [err] npm ERR!     /data/.npm/_logs/2022-09-27T20_09_05_909Z-debug-0.log
2022-09-27T20:09:07.898Z rc=1

Double and triple checked the permissions and they look correct. Tried deleting the .npm folder and node_modules, no change.

Created a new directory and destroyed/recreated the container and I'm still getting the same error. Attempts to npm install from the container shell also fail.

What do you expect to happen?

Packages to update/install successfully.

Please tell us about your environment:

[ ] Platform/OS: Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-48-generic aarch64)

[ ] Browser: Safari

container.log

npm.log

hardillb commented 2 years ago

Did you run the command in the error message (suitably modified to match the path on the host machine)?

hardillb commented 2 years ago

Also which Container version are you using?

rborkow commented 2 years ago

Yes - I ran the chown command on the docker host (no sudo in the container).

Using the latest image tag.

Tried with latest-18, and building a Debian image from scratch with no success.

rborkow commented 2 years ago

OK, I was able to fix this by opening a shell in the container as the root user, and running chown -R 1000:1000 "/data/.npm".

PYSOLO-li commented 1 year ago

I met this issues too, when i install contrib , node-red report same error... almost not fixed this error