# Tests failing due to node\_modules missing something, but it works once I change anything in package.json

**URL:** <https://discuss.circleci.com/t/tests-failing-due-to-node-modules-missing-something-but-it-works-once-i-change-anything-in-package-json/40621>\
**Category:** Build Environment\
**Tags:** npm, nodejs\
**Created:** [July 13, 2021, 6:56pm UTC](https://discuss.circleci.com/t/tests-failing-due-to-node-modules-missing-something-but-it-works-once-i-change-anything-in-package-json/40621 "2021-07-13T18:56:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![karlbecker](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/karlbecker/32/1581_2.png) [@karlbecker](https://discuss.circleci.com/u/karlbecker)\
**Post date:** [July 13, 2021, 6:56pm UTC](https://discuss.circleci.com/t/tests-failing-due-to-node-modules-missing-something-but-it-works-once-i-change-anything-in-package-json/40621/1 "2021-07-13T18:56:47Z")

</div>

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`:

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

```

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

```auto
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:

```auto
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!
