The "next build" always fails at the "Collecting page data..." stage

When building Next.js on render.com, it always fails at the “Collecting page data…” stage.

This has happened a few times in the past, but sometimes it would succeed after a few redo builds.

This time we are building a more complex structure from a previous version.
This may be why the build has not yet succeeded once.

I really don’t know what is causing this, as there are no useful logs and builds in the local environment succeed without problems.

Any hints on how to solve this problem would be great.

os: wsl2 Ubuntu20.04
node.js version: 16.13.0
next.js version: 12.1.6

build command
cross-env NODE_OPTIONS='--max-old-space-size=102400' next build

deploy log

...
Dec 8 11:11:09 AM  [1/5] Validating package.json...
Dec 8 11:11:09 AM  [2/5] Resolving packages...
Dec 8 11:11:11 AM  [3/5] Fetching packages...
Dec 8 11:12:17 AM  info @next/swc-android-arm-eabi@12.1.6: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-android-arm-eabi@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-android-arm-eabi@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info @next/swc-android-arm64@12.1.6: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-android-arm64@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-android-arm64@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info @next/swc-darwin-arm64@12.1.6: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-darwin-arm64@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-darwin-arm64@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info @next/swc-darwin-x64@12.1.6: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-darwin-x64@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-linux-arm-gnueabihf@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-linux-arm-gnueabihf@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-linux-arm64-gnu@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-linux-arm64-gnu@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-linux-arm64-musl@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-linux-arm64-musl@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-win32-arm64-msvc@12.1.6: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-win32-arm64-msvc@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-win32-arm64-msvc@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info @next/swc-win32-ia32-msvc@12.1.6: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-win32-ia32-msvc@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info @next/swc-win32-ia32-msvc@12.1.6: The CPU architecture "x64" is incompatible with this module.
Dec 8 11:12:17 AM  info @next/swc-win32-x64-msvc@12.1.6: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "@next/swc-win32-x64-msvc@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  info fsevents@2.3.2: The platform "linux" is incompatible with this module.
Dec 8 11:12:17 AM  info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
Dec 8 11:12:17 AM  [4/5] Linking dependencies...
Dec 8 11:12:17 AM  warning " > next-auth@4.16.4" has incorrect peer dependency "next@^12.2.5 || ^13".
Dec 8 11:12:17 AM  warning " > raw-loader@4.0.2" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
Dec 8 11:12:17 AM  warning " > @herp-inc/eslint-config-jsx@0.1.0" has unmet peer dependency "eslint-plugin-react@^7.27.0".
Dec 8 11:12:17 AM  warning " > @herp-inc/eslint-config-react@0.1.0" has unmet peer dependency "eslint-plugin-react@^7.27.0".
Dec 8 11:12:17 AM  warning " > @herp-inc/eslint-config-react@0.1.0" has unmet peer dependency "eslint-plugin-react-hooks@^4.3.0".
Dec 8 11:12:17 AM  warning " > @testing-library/react@13.4.0" has incorrect peer dependency "react@^18.0.0".
Dec 8 11:12:17 AM  warning " > @testing-library/react@13.4.0" has incorrect peer dependency "react-dom@^18.0.0".
Dec 8 11:12:17 AM  warning " > babel-loader@8.2.5" has unmet peer dependency "webpack@>=2".
Dec 8 11:12:46 AM  [5/5] Building fresh packages...
Dec 8 11:12:54 AM  $ prisma generate
Dec 8 11:12:55 AM  Environment variables loaded from .env
Dec 8 11:12:55 AM  Prisma schema loaded from prisma/schema.prisma
Dec 8 11:12:56 AM  You can now start using Nexus Prisma in your code. Reference: https://pris.ly/d/nexus-prisma
Dec 8 11:12:57 AM  
Dec 8 11:12:57 AM  ✔ Generated Prisma Client (3.15.2 | library) to ./node_modules/@prisma/client in 491ms
Dec 8 11:12:57 AM  
Dec 8 11:12:57 AM  ✔ Generated Nexus Prisma to ./node_modules/nexus-prisma/dist-cjs/runtime in 286ms
Dec 8 11:12:57 AM  You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
Dec 8 11:12:57 AM  ```
Dec 8 11:12:57 AM  import { PrismaClient } from '@prisma/client'
Dec 8 11:12:57 AM  const prisma = new PrismaClient()
Dec 8 11:12:57 AM  ```
Dec 8 11:12:57 AM  $ cross-env NODE_OPTIONS='--max-old-space-size=102400' next build --no-lint
Dec 8 11:12:58 AM  warn  - Linting is disabled
Dec 8 11:12:58 AM  info  - Loaded env from /opt/render/project/src/.env.production
Dec 8 11:12:58 AM  info  - Loaded env from /opt/render/project/src/.env
Dec 8 11:12:58 AM  warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
Dec 8 11:12:58 AM  info  - Checking validity of types...
Dec 8 11:13:48 AM  info  - Creating an optimized production build...
Dec 8 11:13:48 AM  warn  - using beta Middleware (not covered by semver) - https://nextjs.org/docs/messages/beta-middleware
Dec 8 11:18:42 AM  info  - Compiled successfully
Dec 8 11:18:42 AM  info  - Collecting page data...
Dec 8 11:21:03 AM  error Command failed with exit code 1.
Dec 8 11:21:03 AM  info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Dec 8 11:21:04 AM  error Command failed with exit code 1.
Dec 8 11:21:04 AM  info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Dec 8 11:21:04 AM  ==> Build failed 😞

Hi there,

Thanks for reaching out.

Firstly, you’re telling Node (with --max-old-space-size) that it has ~100GB RAM available, which is hugely incorrect. While the error in the logs doesn’t appear to be a memory-related, that option is wrong. Maybe just try next build as your build command. Node (12+) should be able to work out how much RAM is available and work to that accordingly.

NextJS also appears to have a --debug option for the build, maybe that’s also worth a try to see if it sheds any more light on the error next build --debug (docs)

Kind regards

Alan

Thanks for the reply.

Regarding the --max-old-space-size option, it has already been discussed in the Render community, but we set it to address the “JavaScript heap out of memory” error.
Of course, it may need to be adjusted to an appropriate value.
https://community.render.com/search?expanded=true&q=JavaScript%20heap%20out%20of%20memory

The next build --debug did not give any useful logs.
Incidentally, upgrading the plan to “Pro Plus” and build did not change the results.

Yes, --max-old-space-size comes up quite regularly, but it’s an option to tell Node the constraints of memory it can work within. Adding a huge figure wouldn’t help if this was a memory issue. As I mentioned previously, this doesn’t immediately appear to be a memory issue as the build completes, but with errors. Also, changing the plan changes the memory for the running instance, not the build container.

Please could you share some specific details of the issue you are experiencing that may help us troubleshoot it with you, e.g. any further logs/errors/output, service name/ID, other things you’ve tried, etc. If you don’t want to share these details on the community forum, please feel free to raise a ticket from the “Contact Support” link at the bottom of the Dashboard.

Alan

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.