{"record":{"id":"29d221b047ef3f01","repo":"parcel-bundler/parcel","slug":"could-not-detect-cpu-count","errorCode":null,"errorMessage":"Could not detect cpu count!","messagePattern":"Could not detect cpu count!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/core/workers/src/cpuCount.js","lineNumber":37,"sourceCode":"  let platform = os.platform();\n  let amount = 0;\n\n  if (platform === 'linux') {\n    amount = parseInt(\n      exec('lscpu -p | egrep -v \"^#\" | sort -u -t, -k 2,4 | wc -l'),\n      10,\n    );\n  } else if (platform === 'darwin') {\n    amount = parseInt(exec('sysctl -n hw.physicalcpu_max'), 10);\n  } else if (platform === 'win32') {\n    const str = exec('wmic cpu get NumberOfCores').match(/\\d+/g);\n    if (str !== null) {\n      amount = parseInt(str.filter(n => n !== '')[0], 10);\n    }\n  }\n\n  if (!amount || amount <= 0) {\n    throw new Error('Could not detect cpu count!');\n  }\n\n  return amount;\n}\n\nlet cores;\nexport default function getCores(bypassCache?: boolean = false): number {\n  // Do not re-run commands if we already have the count...\n  if (cores && !bypassCache) {\n    return cores;\n  }\n\n  // $FlowFixMe\n  if (process.browser) {\n    // eslint-disable-next-line no-undef\n    cores = navigator.hardwareConcurrency / 2;\n  }\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/workers/src/cpuCount.js#L19-L55","documentation":"Thrown by detectRealCores when it cannot determine the physical CPU count from platform-specific shell commands (lscpu on Linux, sysctl on macOS, wmic on win32). If all return empty/zero/NaN, the function refuses to return a wrong value.","triggerScenarios":"Running on a platform where lscpu/sysctl/wmic are absent, fail, or output an unparseable format; sandboxed/container environments that block execSync or omit the binaries.","commonSituations":"Minimal Docker images lacking /usr/bin/lscpu; locked-down CI where exec is disabled; Windows without wmic (wmic is deprecated/removed on Windows 11+); BSD/solaris where none of the commands apply; non-English locales producing non-numeric output.","solutions":["Rely on the public getCores() wrapper instead of detectRealCores() — it falls back to os.cpus() and a default of 1.","Install the missing detection tool (lscpu on Linux via util-linux; sysctl is standard on macOS).","On Windows 11+, ensure wmic is available or set PARCEL_WORKERS to a fixed count.","Set PARCEL_WORKERS=<n> env var to bypass detection entirely."],"exampleFix":"// before (direct call — throws in minimal env)\nconst n = detectRealCores();\n\n// after (uses fallback chain)\nimport getCores from '@parcel/workers/src/cpuCount';\nconst n = getCores(); // falls back to os.cpus(), then 1","handlingStrategy":"fallback","validationCode":"// Prefer the public getCores() which already falls back; only validate if calling detectRealCores directly.\nimport os from 'os';\nfunction safeCores() {\n  try { return detectRealCores(); }\n  catch { return Math.max(1, os.cpus().length); }\n}","typeGuard":null,"tryCatchPattern":"try { cores = detectRealCores(); }\ncatch (e) {\n  if (/Could not detect cpu count/.test(e.message)) {\n    cores = os.cpus().length || 1;\n  } else throw e;\n}","preventionTips":["Call getCores() (the cached, fallback-aware wrapper) instead of detectRealCores().","Set PARCEL_WORKERS=<n> to bypass detection in minimal containers.","Ensure lscpu/sysctl/wmic are present in your image; on Windows 11+ account for wmic removal."],"tags":["cpu-detection","platform","worker-farm","env"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}