Persistent Netlify CI Build Failure Due to esbuild's "Cannot read properties of undefined" Error

I am currently deploying my project using the Next.js runtime, but I am encountering persistent failures during the Initializing stage. The issue appears to be tied to esbuild, which returns the error “Cannot read properties of undefined”. Detailed logs are provided below for additional insight.

Site name: hubble-stats
Site ID: d4c352c2-8b01-4895-8c8a-7395966baa18
Build setting:

Runtime: Next.js
Base directory: /
Package directory: apps/hubble-stats
Functions directory: netlify/functions

Repo: GitHub - webb-tools/webb-dapp: Monorepo for the Webb ecosystem.

Log Details:

12:41:40 AM: [5/5] Building fresh packages...
12:41:48 AM: info This package requires node-gyp, which is not currently installed. Yarn will attempt to automatically install it. If this fails, you can run "yarn global add node-gyp" to manually install it.
12:41:48 AM: error An unexpected error occurred: "/opt/build/repo/node_modules/@netlify/build/node_modules/esbuild, /opt/build/repo/node_modules/@netlify/zip-it-and-ship-it/node_modules/esbuild: Cannot read properties of undefined (reading "config")".
12:41:48 AM: info If you think this is a bug, please open a bug report with the information provided in "/opt/buildhome/.config/yarn/global/yarn-error.log".
12:41:48 AM: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
12:41:48 AM: [1/4] Resolving packages...
12:41:49 AM: [2/4] Fetching packages...
12:41:49 AM: [3/4] Linking dependencies...
12:41:49 AM: [4/4] Building fresh packages...
12:41:49 AM: success Installed "node-gyp@9.4.0" with binaries:
12:41:49 AM:       - node-gyp
12:41:54 AM: Failed during stage "Install dependencies": dependency_installation script returned non-zero exit code: 1
12:41:54 AM: Error during Yarn install
12:41:54 AM: Build was terminated: dependency_installation script returned non-zero exit code: 1
12:41:54 AM: Failing build: Failed to install dependencies

Currently experiencing the same issue.

Does this work with npm?

I’m also having this issue frequently.

I haven’t tried it yet.

Please try and let us know.

1 Like

I had the same issue in my ci.

What fixed for me was using yarn install --immutable --immutable-cache --check-cache instead of just yarn install (which seems to be the yarn equivalent of npm ci).

1 Like

Thanks to @rafael-lua, I resolved the issue by incorporating YARN_FLAGS="--immutable --immutable-cache --check-cache" into the environment variables on Netlify. I greatly appreciate your assistance, everyone :raised_hands:.

1 Like

Thanks for coming back and sharing the solution with the community! this will help others who stumble upon your thread in the future. :+1:t6:

1 Like

Unfortunately, I’m still having the same issue, even after adding YARN_FLAGS=“–immutable --immutable-cache --check-cache” to my settings…

I have tried switching node versions, clearing the cache, removing my yarn.lock file, but nothing helps.

hi, mind sharing your site name/build?

Site is https://bankai-website-v4.netlify.app, but it’s a branch deploy: netlify-build-fix. Thus, the URL should be https://netlify-build-fix--bankai-website-v4.netlify.app.

Build log:

9:21:18 AM: [4/4] Building fresh packages...
9:21:22 AM: info This package requires node-gyp, which is not currently installed. Yarn will attempt to automatically install it. If this fails, you can run "yarn global add node-gyp" to manually install it.
9:21:23 AM: error An unexpected error occurred: "/opt/build/repo/node_modules/sharp: Cannot read properties of undefined (reading "config")".
9:21:23 AM: info If you think this is a bug, please open a bug report with the information provided in "/opt/buildhome/.config/yarn/global/yarn-error.log".
9:21:23 AM: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
9:21:23 AM: [1/4] Resolving packages...
9:21:23 AM: [2/4] Fetching packages...
9:21:24 AM: [3/4] Linking dependencies...
9:21:24 AM: [4/4] Building fresh packages...
9:21:24 AM: success Installed "node-gyp@10.0.1" with binaries:
9:21:24 AM:       - node-gyp
9:21:25 AM: Failed during stage "Install dependencies": dependency_installation script returned non-zero exit code: 1
9:21:25 AM: Error during Yarn install
9:21:25 AM: Failing build: Failed to install dependencies

Could you try to remove netlify-cli from your package.json?

That does seem to fix it. At least when building with Yarn 1.22.x

I do have problems with Yarn 4.0.2 now, but that is unrelated to this issue probably. I will create a separate ticket for that. Thanks for now!