Next.js build error (3) was duplicated from Next.js build error (2)
Continue chatting to ask questions about or make changes to it.
An error occurred during deployment. Please fix:
Running build in Washington, D.C., USA (East) – iad1
Build machine configuration: 2 cores, 8 GB
Retrieving list of deployment files...
Previous build caches not available.
Downloading 179 deployment files...
...
}
Export encountered an error on /branches/page: /branches, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null
ELIFECYCLE Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1
The error is clear: TypeError: Cannot read properties of null (reading 'name') in the /branches/page. This suggests something is trying to access the .name property of a null value. Let me check the branches page file:
I found the issue! The problem is on line 25:
const selectedBranch = branches.find(b => b.id === selectedBranchId) || branches[0] || null;When the page tries to render during the static build, branches is an empty array (it hasn't loaded yet), so selectedBranch becomes null. Then when it tries to access selectedBranch.name on line 203, it fails because null has no properties.
The issue is that this is a client component trying to use dynamic state during static generation. Let me also check the branches data file to understand the structure better:
Perfect. Now I understand the issue completely. The problem is that the page initializes with an empty branches array, making selectedBranch null. I need to fix this by ensuring selectedBranch always has a valid value during render. I'll add a null safety check and initialize with the default branches:
I've fixed the deployment error. The issue was that the page component was initializing with an empty branches array, causing selectedBranch to be null during static generation. When the component tried to render selectedBranch.name, it crashed trying to read the .name property of null.
I've fixed it by:
branches state with defaultBranches instead of an empty arrayselectedBranchId with the first branch's ID from defaultBranchesdefaultBranches[0] in the selectedBranch calculation to ensure it always has a valid valueThis ensures that the page always has valid branch data during both build time and runtime, while still allowing the API to update the branches after hydration.
You can send messages while the preview loads