Disable npm cache

后端 未结 3 676
深忆病人
深忆病人 2021-02-12 20:11

Some time ago I had trouble with the npm cache on our build machines. From time to time we had to do npm cache clean by hand, and that solved various issues that we

相关标签:
3条回答
  • 2021-02-12 20:35

    You could fix the problem with parallel builds by creating a new directory for one series of npm commands and set its cache to that empty directory and then remove that directory afterwards. Like:

    export npm_config_cache=$(mktemp -d) 
    npm ...
    ...
    rm -rf $npm_config_cache
    

    This would remove the need for npm cache clean as it would always start out with an empty cache.

    0 讨论(0)
  • 2021-02-12 20:38

    As npm-config documented:

    force§ Default: false Type: Boolean Makes various commands more forceful.

    1. lifecycle script failure does not block progress.
    2. publishing clobbers previously published versions.
    3. skips cache when requesting from the registry.
    4. prevents checks against clobbering non-npm files.

    Maybe use -f / --force is the simplest way to disable npm cache.

    npm install --force
    
    0 讨论(0)
  • 2021-02-12 20:39

    In my case, i was facing similar issue while running multiple instance of 'npm install' on VM used for build(Windows)

    Since it was a VM used only for build there was no other program locking the files. I tried disabling various antivirus settings which didn't worked. "npm cache clear" and "npm cache verify" worked but it was not a right solution for me as i cannot guess when somebody will trigger a build job from Jenkins for different release/environment leading to multiple instance of 'npm install' and hence i cannot add it to the build script nor i can go login to VM and clear/delete the cache folders manually every time.

    Finally, after some research, I ended up running "npm install" with separate cache path for each job using following command:

    npm install --cache path/to/some/folder
    

    Since, all the jobs running at the same time now had a separate cache path rather than the common global path (Users/AppData/Roaming/), this issue got fixed as the jobs were no more trying to lock and access the same file, from the common npm cache.

    Please note you can install a single package with a cache path as follows:

    npm install packageName --cache path/to/some/folder
    

    I was not able to find this way of giving a cache path in npm documentation but i gave it a try and it worked. I am using npm6 and looks like it works since npm5 as @ArchNoob mentioned in the comment

    0 讨论(0)
提交回复
热议问题