question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Caching won't work with node_modules.

See original GitHub issue

CodeBuild 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:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:16

github_iconTop GitHub Comments

4reactions
mparent61commented, Sep 26, 2019

Having same issue using latest CodeBuild v2.0 image and “node 10” runtime installed. Build works fine with caching disabled.

2reactions
cybercussioncommented, May 25, 2022

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.

phases:
  install:
    commands:
      - n 14.19.0
      - echo Installing source NPM dependencies...
      # This project uses angular/cli and pnpm.  "aws/codebuild/standard:5.0" comes with Node 14
      - npm install -g @angular/cli@13.3.6 pnpm@7.1.5
      - pnpm config set store-dir .pnpm-store
      - npm config -g set prefer-offline true
      - npm config -g set cache /root/.npm
      - npm config get cache
      ```
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found