gatsbyjs/gatsby · error

There has been a problem counting the number of CPU cores

Error message

There has been a problem counting the number of CPU cores

What it means

Catch-all thrown by cpuCoreCount's outer try/catch when ANY error escapes the inner logic — most commonly the physical-core detection (getPhysicalCpuCount) throwing on unsupported platforms. It masks the original cause, so the real failure must be inferred from the environment (OS, Node version, GATSBY_CPU_COUNT value).

Source

Thrown at packages/gatsby-core-utils/src/cpu-core-count.ts:52

                `process.env.GATSBY_CPU_COUNT is set to 'logical_cores' but there was a problem finding the number of logical cores`
              )
            }
          }
          break

        case `number`:
          // CPU count === passed in count
          coreCount = coreCountArg
          break

        default:
          break
      }
    }

    return coreCount
  } catch (err) {
    throw new Error(`There has been a problem counting the number of CPU cores`)
  }
}

View on GitHub (pinned to 8b06340921)

Solutions

  1. Set GATSBY_CPU_COUNT to an explicit integer to skip physical-core detection entirely.
  2. On Alpine, install util-linux (lscpu) or switch to a glibc-based Node image.
  3. On Windows 11, install/restore wmic or pin to a Node version whose physical-cpu-count dependency supports the platform.
  4. Check the env var value: an unparseable GATSBY_CPU_COUNT can route into the string branch and indirectly fail.

Example fix

# before: relies on autodetection that fails on minimal image
# (no env var set)
# after
export GATSBY_CPU_COUNT=2
Defensive patterns

Strategy: try-catch

Validate before calling

try { require('os').cpus() } catch { delete process.env.GATSBY_CPU_COUNT; process.env.GATSBY_CPU_COUNT = '1' }

Type guard

const supportsCpuDetection = (): boolean => {
  try { return typeof require('os').cpus().length === 'number' } catch { return false }
}

Try / catch

try {
  cpuCoreCount()
} catch (e) {
  if (/problem counting the number of CPU cores/.test(e.message)) {
    process.env.GATSBY_CPU_COUNT = '1'
    cpuCoreCount()
  } else throw e
}

Prevention

When it happens

Trigger: getPhysicalCpuCount() throws (unsupported platform like some BSD/Alpine combos, missing lscpu/wmic, or a child_process failure during detection) AND GATSBY_CPU_COUNT is unset or invalid; or the inner 'logical_cores' branch itself threw and re-caught here.

Common situations: Alpine/musl images without lscpu; Windows environments where wmic is removed (Win11); restricted CI runners that block child_process spawns used by physical-cpu-count; upgrading Node on an OS the underlying detector does not support.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/5280da2ece7de82e. Report an issue: GitHub.