Caching won't work with node_modules.
See original GitHub issueCodeBuild keeps its cache locally and then symlinks it to our target location as evidenced by this line:
[Container] 2019/02/27 02:24:38 Symlinking: /codebuild/output/src718408252/src/github.com/dashmug/api-tests/node_modules => /codebuild/local-cache/custom/dba27c31aad935787bb275c3e5e4e957708f15386de599eff1db476022cd7e4c
This behaviour, however, breaks Node’s module resolution causing our Node apps to fail.
internal/modules/cjs/loader.js:596
throw err;
^
Error: Cannot find module 'source-map-support'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
This is a widely-known issue. https://github.com/npm/npm/issues/9479 https://github.com/nodejs/node-v0.x-archive/issues/25090
TLDR: node
’s require()
doesn’t work with a symlinked node_modules
directory if the source directory is not named node_modules
.
Because of this bug in node
, having the following in buildspec.yml
will fail:
cache:
paths:
- 'node_modules/**/*'
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:16
Top Results From Across the Web
Why doesn't setting NodeJS module cache to false get ...
Node won't execute the module as long as it is in the require.cache . One way to delete the module from the cache...
Read more >Caching is very slow for Node.JS projects - gitlab-runner
Ideally in this scenario the runner would just unpack the cache created by the previous build job within the test jobs and completely...
Read more >Why isn't my build using the cached node modules?
This is cached from build to build to be reused. When NODE_MODULES_CACHE is true , the buildpack will copy the node modules from...
Read more >Node Cache shouldn't persist when there is a chang...
In our Bitbucket pipeline, we are caching the node modules. ... We are doing this to make sure we don't download the node...
Read more >Caching your Node modules in Azure DevOps - Qxperts
The Cache task takes different inputs. There is a key input, which can be a normal string value or in this case a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having same issue using latest CodeBuild v2.0 image and “node 10” runtime installed. Build works fine with caching disabled.
Thanks @joshhoegen I ended up removing the ‘node_modules/**/*’ and the hang time ended. I used pnpm on this project so I tweaked how that whole thing would work but still tuning. Least it finally let the lint, test jobs run built in < 6 minutes.