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:
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
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).
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 .
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