Build fails on netlify from caching (but builds perfectly locally)

Brand new next.js site, which successfully deploys out of the box (https://sectors-us.netlify.app/). However, on all subsequent builds, hinting at something to do with the lru cache module (ENOENT: no such file or directory, copyfile "/opt/buildhome/.yarn_cache/v6/npm-lru-cache).

This isn’t an issue in the local environment, and Netlify supposedly build it successfully too, so I’m at a lost on how to troubleshoot this further.

4:38:45 PM: Started restoring cached node modules
4:38:45 PM: Finished restoring cached node modules
4:38:45 PM: Installing npm packages using Yarn version 1.22.19
4:38:46 PM: yarn install v1.22.19
4:38:46 PM: [1/4] Resolving packages...
4:38:46 PM: [2/4] Fetching packages...
4:38:46 PM: warning Pattern ["string-width@^4.1.0"] is trying to unpack in the same destination "/opt/buildhome/.yarn_cache/v6/npm-string-width-cjs-4.2.3-269c7117d27b05ad2e536830a8ec895ef9c6d010-integrity/node_modules/string-width-cjs" as pattern ["string-width-cjs@npm:string-width@^4.2.0"]. This could result in non-deterministic behavior, skipping.
4:39:06 PM: [3/4] Linking dependencies...
4:39:07 PM: error An unexpected error occurred: "ENOENT: no such file or directory, copyfile "/opt/buildhome/.yarn_cache/v6/npm-lru-cache-6.0.0-6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94-integrity/node_modules/lru-cache/LICENSE" -> "/opt/build/repo/node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache/LICENSE"".
4:39:07 PM: info If you think this is a bug, please open a bug report with the information provided in "/opt/build/repo/yarn-error.log".
4:39:07 PM: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
4:39:10 PM: Error during Yarn install
4:39:10 PM: Failing build: Failed to install dependencies
4:39:10 PM: Failed during stage "Install dependencies": dependency_installation script returned non-zero exit code: 1

Does it work with npm?

I’m seeing this myself. I was getting a lot of bizarre errors until I reached this one. First it was trying to download a version of a dependency that was a fork instead of the original (probably my fault switching from fork to main but yarn.lock not updating). Then it had a problem getting that dependency because it claimed to require git ssh and didn’t have access (even though public repo and listed as normal npmjs.com package name not github url). I figured out a way to remove those dependencies completely and now it’s failing on this weird cache error almost the exact same as yours.

9:58:33 PM: [3/5] Fetching packages...
9:58:33 PM: error https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.3.0.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOENT: no such file or directory, open "/opt/buildhome/.yarn_cache/v6/npm-@ampproject-remapping-2.3.0-ed441b6fa600072520ce18b43d2c8cc8caecc7f4-integrity/node_modules/@ampproject/remapping/dist/types/remapping.d.ts""
9:58:33 PM: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
9:58:44 PM: error https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz: ENOENT: no such file or directory, open "/opt/buildhome/.yarn_cache/v6/npm-escape-html-1.0.3-0258eae4d3d0c0974de1c169188ef0051d1d1988-integrity/node_modules/escape-html/.yarn-tarball.tgz"
9:59:02 PM: Failed during stage "Install dependencies": dependency_installation script returned non-zero exit code: 1
9:59:02 PM: Error during Yarn install
9:59:02 PM: Failing build: Failed to install dependencies

Tried Clear cache and retry with latest branch commit but same error.

Hi @okwme,

Thanks for reaching out!

Could you let us know the site name that you’re having this issue with? Such as sitename.netlify.app, that’ll help the team see additionally information about the site. Thanks!

hello i have same error (i think) and my site domain is 703.netlify.app

@Shio703, please refer to your build logs, they seem to have a clear message about the failure and also a solution:

1 Like

Thank you very much, sorry for my inattention :heart: