Running npm ci without deleting old node_modules folder #20104


(Baptiste Gaillard) #1

Hi, we would like to use the new npm ci command in our Jenkins build but we cannot delete the node_modules folder.

I found a description of the issue we encounter in the following archived Github issue : https://github.com/npm/npm/issues/20104.

We have an other use case where the whole deletion of the node_modules directory is problematic.

To speed-up our npm install executions in Jenkins we map a tmpfs Docker volume to the node_modules folder.

Our configuration is similar to the following (Jenkins starts a Docker container and then npm ci is executed inside it) :

docker run -t -d -u 500:500 --tmpfs=/project_directory/node_modules:exec,gid=500,uid=500 -v /home/ec2-user/efs/.npm:/.npm ... node:11

With this mapping our npm install commands are very very fast because all file copies are done completely in memory.

But because the tmpfs volume is created at container start it cannot be deleted by npm ci after.

To solve our problem it would require one of the following

  • Prevent the node_modules to be deleted
  • Delete node_module/**/* files instead of delete the node_modules folder.

What do you think about that ?

Thanks,

Baptiste


(Kat Marchán) #2

I would take a patch that does rm -rf node_modules/**/* as the new default for npm ci, tbh. It’s a thing that’s been mentioned before.


(Baptiste Gaillard) #3

Hi @zkat and thanks for your reactivity on this !

Ok, I think I found the mentioned you talked about, here are the links I found to add a little more context for others who would need this feature too :

Thanks,

Baptiste