When you run your pipeline without modifying dependencies, GitLab CI restores the cache using a key derived from the SHA of package-lock.json.
Copy
Ask AI
$ gitlab-runner --versionRunning with gitlab-runner 16.6.0~beta.105.gd263193 (d263193)…Restoring cacheChecking cache for node_modules-eb6511c24d2374382b3f5272690bfa2122-non_protected…Downloading cache from https://storage.googleapis.com/.../node_modules-eb6511c24d2374382b3f5272690bfa2122-non_protectedSuccessfully extracted cache…$ npm installup to date, audited 365 packages in 1s31 packages are looking for funding…$ npm test
This confirms that the existing cache was restored and used for the npm install step.
GitLab CI uses the contents of package-lock.json to generate a unique cache key. Any modification to this file produces a new key.
After pushing, the pipeline’s unit testing job will attempt to restore the cache with a newly generated key. Because package-lock.json changed, GitLab cannot find the old cache.
Copy
Ask AI
Restoring cacheChecking cache for node_modules-89184f59d584d146040c768c579d223d8bc7ab-non_protected…WARNING: file does not existFailed to extract cache…Saving cache for successful jobUploading artifacts for successful jobJob succeeded
Phase
Cache Key (SHA)
Outcome
Before dependency change
eb6511c24d2374382b3f5272690bfa2122
Hit
After adding nodemon
89184f59d584d146040c768c579d223d8bc7ab
Miss
Because the key changed, GitLab reports a cache miss and proceeds to install dependencies from scratch.
$ npm installadded 364 packages, and audited 385 packages in 7s…$ npm test> Solar [email protected] test> mocha app-test.js --timeout 10000 --reporter mocha-junit-reporter --exitServer successfully running on port - 3000
After tests pass, GitLab saves a new cache under the updated key:
Copy
Ask AI
Saving cache for successful jobCreating cache node_modules-89184f59d584d146040c768c579d223d8bc7ab-non_protected…node_modules: found 6041 matching artifact files and directoriesUploading cache.zip to https://storage.googleapis.com/.../node_modules-89184f59d584d146040c768c579d223d8bc7ab-non_protectedCreated cache
Notice the increase in cached files (from ~5700 to ~6040) after adding nodemon.
By following this approach, you ensure GitLab CI invalidates and regenerates caches whenever your dependency lockfiles change, keeping your pipelines fast and reliable.