Tests failing due to node_modules missing something, but it works once I change anything in package.json

I tried posting this in the Caching Dependencies section, but I think I should post it elsewhere, since it continues to happen and I didn’t have an answer there. I could really use some help!

In our NodeJS app (call it our_app), we have one dependency (call it our_dependency, one we maintain in a private repo on GitHub) that has a prepare script in its package.json. Here’s a snippet from our_dependency's package.json:

  "scripts": {
    "build": "tsc",
    "prepare": "npm run build",
    ...
  },

Recently, builds for our_app started failing, with an error of:

WORKER STDERR: Unhandled rejection Error: Cannot find module '/root/*********/our_app/node_modules/our_dependency/build/index.js'. Please verify that the package.json has a valid "main" entry

The lack of a file in node_modules/our_dependency/build/ makes me think CircleCI has changed something with how it’s storing data created from a prepare script. We changed nothing related to this dependency, and I re-ran a build that passed perfectly fine a week ago, and it now fails with the same error.

Once I modified the package.json in our_app , which I believe forces a clean npm install from scratch, then the build passes.

The config.yml for our_app does indeed use restore_cache. Here’s a relevant snippet from that file:

version: 2.1

package-cache: &package-cache
  key: npm-cache-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
...
steps:
    - checkout
    - restore_cache:
        <<: *package-cache
    - run:
        name: Install npm dependencies
        command: |
          # npm set used to set a variable or two
          npm install
    - save_cache:
        <<: *package-cache
        paths:
        - ./node_modules
...

Anyone else seen this issue, or anyone from CircleCI who can help explain if something changed in the system with regards to this? Seems like if a prepare script ran, anything within node_modules, including the contents of node_modules/our_dependency/build/, should have been maintained in CircleCI’s cache, correct?

One last note: the build/ directory is set to be ignored in the our_dependency repo. Think that could that be causing any weirdness with CircleCI’s caching?

Thanks!