[FEATURE] Do not remove node_modules on npm ci
Problem
What / Why I would really like to see a flag like `npm ci --keep` to do an incremental update on our buildserver as this would speed up our deployments a lot. Like suggested before on github and on the community. The last update was on the 7th of October that this was being reviewed by the cli team. Could someone post an update on this? :-)
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Implement npm ci --keep Flag for Incremental Updates
The current behavior of 'npm ci' is to remove the existing 'node_modules' directory before installing dependencies, which can lead to longer deployment times on build servers. The proposed 'npm ci --keep' flag would allow for incremental updates by retaining the existing 'node_modules' directory, thus speeding up the deployment process.
Awaiting Verification
Be the first to verify this fix
- 1
Create a Feature Request
Submit a formal feature request to the npm CLI team to add the '--keep' flag to the 'npm ci' command. This request should include detailed use cases and the benefits of implementing this feature.
bashnpm feature request --title 'Add --keep flag to npm ci' --description 'Allow incremental updates without removing node_modules' - 2
Implement a Local Workaround
As a temporary solution, create a script that backs up the 'node_modules' directory before running 'npm ci' and restores it afterward. This can help speed up deployments until the feature is implemented.
bash#!/bin/bash # Backup node_modules cp -r node_modules node_modules_backup # Run npm ci npm ci # Restore node_modules cp -r node_modules_backup/* node_modules/ # Cleanup backup rm -rf node_modules_backup - 3
Monitor Community Feedback
Engage with the npm community on GitHub and other forums to gather support for the feature request. Encourage others to share their use cases and the impact of the current behavior on their workflows.
bashgit commit -m 'Encourage community feedback on npm ci --keep feature request' - 4
Test the Workaround
Run the backup and restore script in a staging environment to ensure it works as expected and does not introduce any issues with the existing dependencies.
bash./backup_and_restore.sh
Validation
To confirm the fix worked, monitor the deployment times before and after implementing the workaround. Additionally, check for any errors during the backup and restore process to ensure that the integrity of the 'node_modules' directory is maintained.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep