denoland/deno · error · Error

Using cpu-features module is currently not supported

Error message

Using cpu-features module is currently not supported

What it means

Deno's .node native-addon loader explicitly refuses the cpu-features package: its native CPU-capability probing is unsupported under Deno, so loading cpufeatures.node throws this Error rather than crashing deeper in NAPI. It is almost never a direct dependency - packages like ssh2 pull it in as an optional native add-on.

Source

Thrown at ext/node/polyfills/01_require.js:2314

// Async hooks wrappers for NAPI - called from Rust via V8 function calls.
function napiAsyncHooksEmitInit(asyncId, type, triggerAsyncId, resource) {
  internalAsyncHooksEmitInit(asyncId, type, triggerAsyncId, resource);
}
function napiAsyncHooksEmitBefore(asyncId) {
  internalAsyncHooksEmitBefore(asyncId);
}
function napiAsyncHooksEmitAfter(asyncId) {
  internalAsyncHooksEmitAfter(asyncId);
}
function napiAsyncHooksEmitDestroy(asyncId) {
  internalAsyncHooksEmitDestroy(asyncId);
}

// Native extension for .node
Module._extensions[".node"] = function (module, filename) {
  if (filename.endsWith("cpufeatures.node")) {
    throw new Error("Using cpu-features module is currently not supported");
  }
  module.exports = op_napi_open(
    filename,
    globalThis,
    buffer.Buffer.from,
    reportError,
    napiAsyncHooksEmitInit,
    napiAsyncHooksEmitBefore,
    napiAsyncHooksEmitAfter,
    napiAsyncHooksEmitDestroy,
  );
};

function createRequireFromPath(filename, sourceURL) {
  const proxyPath = op_require_proxy_path(filename) ?? filename;
  const mod = new Module(proxyPath);
  mod.filename = proxyPath;
  mod.paths = Module._nodeModulePaths(mod.path);

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Install dependencies without optionals so cpu-features is never fetched: npm install --omit=optional
  2. For ssh2: it works without cpu-features (pure-JS fallback) - update to a version that guards the optional require and ensure the dep is absent
  3. If CPU feature detection is genuinely needed, approximate with os.cpus()/navigator.hardwareConcurrency or run that workload under Node
  4. Stub it via package.json overrides so any transitive require resolves to an empty module

Example fix

// before
// package.json: { "dependencies": { "ssh2": "^1.16" } }
// default install pulls optional cpu-features; require("ssh2") throws

// after
// install skipping optional deps:
//   npm install --omit=optional
// or pin it away in package.json:
{
  "dependencies": { "ssh2": "^1.16" },
  "overrides": { "cpu-features": "npm:@favware/skip-dependency-noop@1.2.2" }
}
Defensive patterns

Strategy: fallback

Validate before calling

function loadCpuFeatures() {
  try {
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    return require("cpu-features");
  } catch {
    return null; // unsupported under Deno - caller falls back to os.cpus()
  }
}

const cpu = loadCpuFeatures();
const cores = cpu ? cpu.cores : require("node:os").cpus().length;

Try / catch

try {
  require("cpu-features");
} catch (e) {
  if (e instanceof Error && e.message.includes("cpu-features module is currently not supported")) {
    // Deno: proceed without native CPU feature detection
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: require('ssh2') (or another package with cpu-features as an optional dependency) where the resolver installed cpu-features and the package requires it during initialization; directly require('cpu-features').

Common situations: Using ssh2 for SFTP/SSH from Deno with npm compatibility; projects previously developed on Node where optional native deps got built and cached.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/869654329386cbf3. Report an issue: GitHub.