{"record":{"id":"5280da2ece7de82e","repo":"gatsbyjs/gatsby","slug":"there-has-been-a-problem-counting-the-number-of-cp","errorCode":null,"errorMessage":"There has been a problem counting the number of CPU cores","messagePattern":"There has been a problem counting the number of CPU cores","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-core-utils/src/cpu-core-count.ts","lineNumber":52,"sourceCode":"                `process.env.GATSBY_CPU_COUNT is set to 'logical_cores' but there was a problem finding the number of logical cores`\n              )\n            }\n          }\n          break\n\n        case `number`:\n          // CPU count === passed in count\n          coreCount = coreCountArg\n          break\n\n        default:\n          break\n      }\n    }\n\n    return coreCount\n  } catch (err) {\n    throw new Error(`There has been a problem counting the number of CPU cores`)\n  }\n}\n","sourceCodeStart":34,"sourceCodeEnd":55,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-core-utils/src/cpu-core-count.ts#L34-L55","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set GATSBY_CPU_COUNT to an explicit integer to skip physical-core detection entirely.","On Alpine, install util-linux (lscpu) or switch to a glibc-based Node image.","On Windows 11, install/restore wmic or pin to a Node version whose physical-cpu-count dependency supports the platform.","Check the env var value: an unparseable GATSBY_CPU_COUNT can route into the string branch and indirectly fail."],"exampleFix":"# before: relies on autodetection that fails on minimal image\n# (no env var set)\n# after\nexport GATSBY_CPU_COUNT=2","handlingStrategy":"try-catch","validationCode":"try { require('os').cpus() } catch { delete process.env.GATSBY_CPU_COUNT; process.env.GATSBY_CPU_COUNT = '1' }","typeGuard":"const supportsCpuDetection = (): boolean => {\n  try { return typeof require('os').cpus().length === 'number' } catch { return false }\n}","tryCatchPattern":"try {\n  cpuCoreCount()\n} catch (e) {\n  if (/problem counting the number of CPU cores/.test(e.message)) {\n    process.env.GATSBY_CPU_COUNT = '1'\n    cpuCoreCount()\n  } else throw e\n}","preventionTips":["Set GATSBY_CPU_COUNT to an integer on Alpine/Win11/sandboxed runtimes.","Install lscpu (util-linux) on Alpine images.","Restore wmic on Windows 11 or pin a compatible Node version."],"tags":["cpu-cores","gatsby-core-utils","platform","container"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}