Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node_modules caching is harmfull when using npm ci #75

Open
WolfSoko opened this issue Nov 21, 2024 · 2 comments
Open

node_modules caching is harmfull when using npm ci #75

WolfSoko opened this issue Nov 21, 2024 · 2 comments
Assignees

Comments

@WolfSoko
Copy link

WolfSoko commented Nov 21, 2024

Beside caching node_modules with your caching workflow step the Agents for my repo needed always too long (4mins) to run the install-node-modules action.

The problem comes from the usage of npm ci to install node_modules based on the package-lock.json:

In an CI environment using npm ci sound correct, but the upfront caching of node_modules folder makes no sense at all.
It even takes more time because due to npm documentation npm ci deletes the node_modules folder for a clean installation process. @see npm ci documentation what takes more time when the folder is filled after a cache hit.

What can be cached to speed up npm ci is the global node cache $HOME/.npm from which npm ci can pull the packages faster.

I created my agents based on your runner templates. So I guess a lot of people are facing the same problem.

As a workaround I just replaced my usage of your install-node-modules workflow-step with a simple script that just runs npm install.
It brought down the execution time to 4sec when hitting the cache!
Fast execution was more important for me then consistency of the dependencies.

@JamesHenry
Copy link
Collaborator

The actions/cache documentation also say that it is recommended to not cache node_modules and instead cache the central cache (path dependent on OS): https://github.com/actions/cache/blob/main/examples.md#node---npm

@barbados-clemens please can you take a look?

@WolfSoko
Copy link
Author

WolfSoko commented Nov 21, 2024

@JamesHenry That is exactly what the github setup-node action does when caching is configured to npm.

It leverages npm config get cache to determine the central cache folder and only caches that.

@barbados-clemens
As a suggestion a possible and maybe fastest and dependency consistent method might be to cache node_modules and central cache.

Then try with npm install.

if npm install changes package-lock.json revert changes and fallback to npm ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants