iOfficeAI/OfficeCLI · error · OfficeCliError

127

127

Error message

officecli CLI not found: {bin} is not on PATH nor in the default install location (~/.local/bin, or %LOCALAPPDATA%\OfficeCLI on Windows). This SDK only forwards commands to the officecli binary, which must be installed separately. Install it:
    node -e "require('@officecli/sdk').install()"   # runs the official installer
    # or: curl -fsSL https://d.officecli.ai/install.sh | bash
    # (npm i @officecli/sdk already pulls @officecli/officecli, which bundles the binary)
Already installed elsewhere? pass { binary: "/path/to/officecli" }.

What it means

Thrown by runCli() (code 127) when spawnSync fails with ENOENT — the officecli binary is neither on PATH nor in the default install locations. The SDK is only a thin pipe-forwarding shell; it never bundles a binary itself, so the CLI must be installed separately. The message gives the exact installer commands and the {binary} override.

Source

Thrown at sdk/node/index.js:428

  if (IS_WIN && /\.(cmd|bat)$/i.test(binary)) {
    // Node refuses to spawn a .cmd/.bat directly without a shell since
    // CVE-2024-27980 (raises EINVAL). Run it through cmd.exe ourselves,
    // quoting each token so paths with spaces survive — shell:true would
    // join the args unquoted and break on the first space. Mirrors Node's
    // own shell idiom (cmd /d /s /c "<line>" + windowsVerbatimArguments)
    // but with the per-token quoting shell:true omits.
    const line = [binary, ...argv].map(quoteForCmd).join(' ');
    cmd = process.env.ComSpec || 'cmd.exe';
    args = ['/d', '/s', '/c', `"${line}"`];
    opts.windowsVerbatimArguments = true;
  }
  return spawnSync(cmd, args, opts);
}

function runCli(binary, argv) {
  const r = spawnCli(binary, argv);
  if (r.error && r.error.code === 'ENOENT') {
    throw new OfficeCliError(127, MISSING_CLI.replace('{bin}', JSON.stringify(binary)));
  }
  if (r.error) throw new OfficeCliError(-1, r.error.message);
  return r;
}

// Probe a resolved binary by running `<binary> --version`: true iff it actually
// runs and exits 0. We accept only a WORKING officecli — a present-but-broken
// file (wrong arch, stale/again-renamed shim, corrupt download) must not be
// used, and conversely a working officecli on PATH must not be shadowed by a
// needless auto-install. Output is discarded.
function probeVersion(binPath) {
  const r = spawnCli(binPath, ['--version'], { stdio: ['ignore', 'ignore', 'ignore'] });
  return !r.error && r.status === 0;
}

// ---------------------------------------------------------------- the shell
class Document {
  constructor(filePath, binary = 'officecli', timeoutMs = 30000) {

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Run the official installer: `node -e "require('@officecli/sdk').install()"` (PowerShell on Windows, install.sh via bash elsewhere).
  2. Install the bundling npm package: `npm i @officecli/officecli` (its postinstall fetches the binary) or `curl -fsSL https://d.officecli.ai/install.sh | bash`.
  3. Pass the explicit location: open(file, { binary: '/abs/path/to/officecli' }).
  4. Ensure the install directory is on PATH for the user running Node.

Example fix

// before: oc.open('f.xlsx') -> [exit 127] officecli CLI not found...
// after: install, or point at an explicit binary
await new Promise(r => require('@officecli/sdk').install()); // or: npm i @officecli/officecli
const doc = await oc.open('f.xlsx', { binary: '/usr/local/bin/officecli' });
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the binary exists & is runnable before any open()/create()
const { spawnSync } = require('child_process');
const fs = require('fs');
function ensureCli(path) {
  if (!fs.existsSync(path) || spawnSync(path, ['--version'], {stdio:['ignore','ignore','ignore']}).status !== 0) {
    require('@officecli/sdk').install(); // runs the official installer
  }
}

Prevention

When it happens

Trigger: Calling open()/create() (or any path that spawns the CLI) before officecli is installed; PATH does not include ~/.local/bin (Unix) or %LOCALAPPDATA%\OfficeCLI (Windows); autoInstall was disabled and no binary was pre-staged.

Common situations: Fresh machine/CI image without the binary; a stripped-down container where the install location isn't on PATH; the binary uninstalled but node_modules left behind; running as a user whose PATH differs from the install-time user.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/79674162022f654a. Report an issue: GitHub.