parcel-bundler/parcel · warning · Error

Could not detect cpu count!

Error message

Could not detect cpu count!

What it means

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.

Source

Thrown at packages/core/workers/src/cpuCount.js:37

  let platform = os.platform();
  let amount = 0;

  if (platform === 'linux') {
    amount = parseInt(
      exec('lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l'),
      10,
    );
  } else if (platform === 'darwin') {
    amount = parseInt(exec('sysctl -n hw.physicalcpu_max'), 10);
  } else if (platform === 'win32') {
    const str = exec('wmic cpu get NumberOfCores').match(/\d+/g);
    if (str !== null) {
      amount = parseInt(str.filter(n => n !== '')[0], 10);
    }
  }

  if (!amount || amount <= 0) {
    throw new Error('Could not detect cpu count!');
  }

  return amount;
}

let cores;
export default function getCores(bypassCache?: boolean = false): number {
  // Do not re-run commands if we already have the count...
  if (cores && !bypassCache) {
    return cores;
  }

  // $FlowFixMe
  if (process.browser) {
    // eslint-disable-next-line no-undef
    cores = navigator.hardwareConcurrency / 2;
  }

View on GitHub (pinned to 59484858a1)

Solutions

  1. Rely on the public getCores() wrapper instead of detectRealCores() — it falls back to os.cpus() and a default of 1.
  2. Install the missing detection tool (lscpu on Linux via util-linux; sysctl is standard on macOS).
  3. On Windows 11+, ensure wmic is available or set PARCEL_WORKERS to a fixed count.
  4. Set PARCEL_WORKERS=<n> env var to bypass detection entirely.

Example fix

// before (direct call — throws in minimal env)
const n = detectRealCores();

// after (uses fallback chain)
import getCores from '@parcel/workers/src/cpuCount';
const n = getCores(); // falls back to os.cpus(), then 1
Defensive patterns

Strategy: fallback

Validate before calling

// Prefer the public getCores() which already falls back; only validate if calling detectRealCores directly.
import os from 'os';
function safeCores() {
  try { return detectRealCores(); }
  catch { return Math.max(1, os.cpus().length); }
}

Try / catch

try { cores = detectRealCores(); }
catch (e) {
  if (/Could not detect cpu count/.test(e.message)) {
    cores = os.cpus().length || 1;
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/29d221b047ef3f01. Report an issue: GitHub.