NPM cache lives on a read only partition
Describe the bug the cache for npm lives on a read only part of the file system. so npm install will not work cause npm is not able to write into its cache
To Reproduce Steps to reproduce the behavior:
- ssh into the system
- cd to
/usr/local/addons/yourownaddondir npm install packageofyourchoice- error comes up:
npm ERR! code EROFS
npm ERR! syscall mkdir
npm ERR! path /root/.npm
npm ERR! errno -30
npm ERR! rofs EROFS: read-only file system, mkdir '/root/.npm'
npm ERR! rofs Often virtualized file systems, or other file systems
npm ERR! rofs that don't support symlinks, give this error.
Expected behavior
npm install will do its job
Screenshots N/A
System information (please complete the following information): its not hardware related
Additional context a suggested solution:
move the cache to /usr/local/.... or any other persistent writable part of the system by default
As an example to /usr/local/addons/npm/
there has to be a file named .npmrc in /root
cache=/usr/local/addons/npm/.npm
init-module=/usr/local/addons/npm/.npm-init.js
userconfig=/usr/local/addons/npm/.npmrc
path=/usr/local/addons/npm/.npm
Thanks for the suggestion. But why not simply move the npm cache to /tmp so that after a reboot it is gone again. Not being a nodejs/npm expert, but in the end this should only be a cache, right? And what is the init-module= setting in the .npmrc for? And what does path= actually define?
https://docs.npmjs.com/cli-commands/cache.html says:
A note about the cache’s design§
The npm cache is strictly a cache: it should not be relied upon as a persistent and reliable data store for package data. npm makes no guarantee that a previously-cached piece of data will be available later, and will automatically delete corrupted contents. The primary guarantee that the cache makes is that, if it does return data, that data will be exactly the data that was inserted.
so moving this to /tmp should be fine
Edit: i will try this on one of my dev systems and give a feedback here
Great, I also thought so. The only questions remaining are then:
- how to clear the cache just in case it starts to occupy more than the totally available RAM?
- or is there a possibility to completly disable the cache using a npmrc setting?
- what do the other settings (init-module, path, etc.) exactly mean?
ok, there is a --no-cache option for npm-i .. but this will create a folder named "false" at the current directory (/usr/local/addons/hap-homematic in my case which is the installation folder) with all the caching data .. i can remove this folder for my addon so i am fine with that approach ..
Nope, I challenge a global solution here and not just for your addon. thus, I will add a /usr/etc/npmrc file with some suggested settings to move the cache to /tmp so that other developers can benefit from this as well. So please elaborate what all the init-module, path settings in npmrc mean if you would like to help.
u have just set the cache to tmp for npm i to work.
So /root/.npmrc with one line
cache=/tmp
will do the job.
init-module is for creating new modules which is for development.
For the example at the issue decription i took my .npmrc pointed the paths to a writable folder and npm i was able to run. But after digging a little bit deeper it turns out just pointing the cache to a writable folder is enough
Edit: Removing the cache by npm cache clear comes up with the following:
npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use
npm install --cache /tmp/empty-cacheto use a temporary cache instead of nuking the actual one.
So the approach above to set the cache to a persistent folder maybe not such a bad idea
I still prefer to move the cache to /tmp because I don't want such garbage on the presistent sd card or normal installation which where the backup will probably include it or it might corrupt an sd card but this is just a cache.
Thans for the init-module explaination. And what is path= all about?
i did not found anything about this