Skip to content

🐞 CircleCI / GhA :: JavaScript heap out of memory #2524

@frankleighintercom

Description

@frankleighintercom

Describe the bug
We recently incorporated Sanity CMS into our NextJS Application using the npx sanity@latest init command.

It scaffolded out our CMS studio perfectly within the app router under (sanity)/studio/[[...tool]]/.

The app and studio run in dev perfectly and when building locally it's all good.

When we then go to build the app on a CI like Circle or with Github actions - we run into an error:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

To Reproduce

  1. Create a nextJS application
  2. run npx sanity@latest init
  3. Let the cli tool do it's thing
  4. Run a build from within circleCI or a Github action

Expected behavior

The build should not run out of memory.

Screenshots
If applicable, add screenshots to help explain your problem.

Which versions of Sanity are you using?

@sanity/cli (global)   3.89.0 (latest: 3.93.0)
@sanity/image-url       1.1.0 (up to date)
@sanity/ui            2.15.18 (latest: 2.16.2)
@sanity/vision         3.92.0 (latest: 3.93.0)
sanity                 3.89.0 (latest: 3.93.0)

What operating system are you using?
Docker

Which versions of Node.js / npm are you running?

9.8.1
v18.18.2

Additional context

"next": "15.3.0-canary.8",
"next-sanity": "^9.11.1",

It seems that either removing the instantiation of <NextSanity ... /> or removing the route created by sanity solves the issue but that means we can't have our CMS studio on our domain.

Full Github action logs:

> next build --no-lint
 ⚠ Linting is disabled.
⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
   ▲ Next.js 15.3.0-canary.[8](https://github.com/intercom/fin-ai/actions/runs/15782394098/job/44490996655?pr=797#step:6:9)
   - Experiments (use with caution):
     ✓ viewTransition
     · clientTraceMetadata
   Creating an optimized production build ...
[@sentry/nextjs - Node.js] Warning: No auth token provided. Will not create release. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/
[@sentry/nextjs - Node.js] Warning: No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/
[@sentry/nextjs - Node.js] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
<--- Last few GCs --->
[2182:0x2ec[9](https://github.com/intercom/fin-ai/actions/runs/15782394098/job/44490996655?pr=797#step:6:10)ea30]   135773 ms: Scavenge 1844.5 (2075.3) -> 1832.9 (2075.3) MB, 14.1 / 0.0 ms  (average mu = 0.275, current mu = 0.280) allocation failure; 
[2182:0x2ec9ea30]   135825 ms: Scavenge 1844.7 (2075.4) -> 1834.0 (2075.4) MB, 6.8 / 0.0 ms  (average mu = 0.275, current mu = 0.280) allocation failure; 
[2182:0x2ec9ea30]   135894 ms: Scavenge 1849.9 (2077.7) -> 1838.6 (2077.7) MB, 6.1 / 0.0 ms  (average mu = 0.275, current mu = 0.280) allocation failure; 
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb85bc0 node::Abort() [node]
 2: 0xa94834  [node]
 3: 0xd66d[10](https://github.com/intercom/fin-ai/actions/runs/15782394098/job/44490996655?pr=797#step:6:11) v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xd670b7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xf447c5  [node]
 6: 0xf456c8 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
 7: 0xf55bd3  [node]
 8: 0xf56a48 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 9: 0xf313ae v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0xf32777 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
[11](https://github.com/intercom/fin-ai/actions/runs/15782394098/job/44490996655?pr=797#step:6:12): 0xf1394a v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
[12](https://github.com/intercom/fin-ai/actions/runs/15782394098/job/44490996655?pr=797#step:6:13): 0x12d8caf v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
13: 0x1705b39  [node]
Aborted (core dumped)
 ELIFECYCLE  Command failed with exit code [13](https://github.com/intercom/fin-ai/actions/runs/15782394098/job/44490996655?pr=797#step:6:14)4.
Error: Process completed with exit code 134.

The action itself:

name: Test

on:
  push:
    branches: [poc/sanity-cms-merge-styles]
  pull_request:
    branches: [poc/sanity-cms-merge-styles]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "18.18.2"

      - name: Install PNPM
        run: |
          sudo corepack enable
          corepack prepare [email protected] --activate
      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Build
        run: pnpm run build

app/(sanity)/studio/[[...tool]]/page.tsx

/**
 * This route is responsible for the built-in authoring environment using Sanity Studio.
 * All routes under your studio path is handled by this file using Next.js' catch-all routes:
 * https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes
 *
 * You can learn more about the next-sanity package here:
 * https://github.com/sanity-io/next-sanity
 */
import { NextStudio } from "next-sanity/studio";

export { metadata, viewport } from "next-sanity/studio";

import config from "../../../../../sanity.config";

export default function StudioPage() {
  return <NextStudio config={config} />;
}

sanity.config

"use client";

/**
 * This configuration is used to for the Sanity Studio that's mounted on the `/app/studio/[[...tool]]/page.tsx` route
 */

import { visionTool } from "@sanity/vision";
import { structureTool } from "sanity/structure";
import { defineConfig } from "sanity";
import { graphiQLTool } from "sanity-plugin-graphiql";
// Go to https://www.sanity.io/docs/api-versioning to learn how API versioning works
import { apiVersion, dataset, projectId } from "./src/sanity/env";
import { schema } from "./src/sanity/schemaTypes";
import { structure } from "./src/sanity/structure";

export default defineConfig({
  basePath: "/studio",
  projectId,
  dataset,
  // Add and edit the content schema in the './sanity/schemaTypes' folder
  schema,
  plugins: [
    structureTool({ structure }),
    // Vision is for querying with GROQ from inside the Studio
    // https://www.sanity.io/docs/the-vision-plugin
    visionTool({ defaultApiVersion: apiVersion }),
    // graphiQLTool({
    //   apiVersion: "2021-10-21",
    // }),
  ],
});

This error is causing a complete blockage of our ability to encorporate a CMS into our application (the way we want to)

Alternatively we can have the CMS run on a separate server BUT this plugin should already enable us to have it live on the same domain...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions