Skip to content

v8.0.0

Latest

Choose a tag to compare

@satazor satazor released this 29 Nov 05:14
· 4 commits to master since this release

Upgrading

cross-spawn 8 requires Node.js 22.13 or later. Node.js 8 to 22.12 can keep using cross-spawn 7 (npm install cross-spawn@7), which still gets security fixes.

It's now an ES module with named exports only: there's no default export, and spawn.sync() is now spawnSync(). CommonJS code can still require() it:

// Before
const spawn = require('cross-spawn');

spawn('npm', ['install']);
spawn.sync('npm', ['install']);

// After
import { spawn, spawnSync } from 'cross-spawn'; // Or: const { spawn, spawnSync } = require('cross-spawn');

spawn('npm', ['install']);
spawnSync('npm', ['install']);
  • TypeScript types are included, the same as Node's spawn and spawnSync, so @types/cross-spawn can be removed.
  • Only the package itself can be imported, not its internal files, such as cross-spawn/lib/parse, and the private _parse and _enoent exports are gone.
  • Jest only loads ES modules required from CommonJS tests on Node.js 24.9+ with --experimental-vm-modules, or with a transform. jest.mock('cross-spawn', factory) keeps working.

Breaking changes

  • Node.js 22.13 or later, the first release that can require() an ES module without a warning.
  • ES module with named exports only, see above.
  • spawnSync() results leave error unset when there's no error, like Node's, instead of setting it to null (#151).
  • Windows: a command is a single program (#150). As on other platforms, spawn('npm install') now fails with ENOENT: pass the arguments separately.
  • Windows: commands that can't be run safely through cmd.exe throw a TypeError with the ERR_INVALID_ARG_VALUE code: commands containing double quotes, ^ or %, ending with a dot or whitespace, or resolving to a file whose path contains ^ or %.
  • Windows: ENOENT comes from Node.js (#104). Commands that don't exist are no longer run through cmd.exe, and an exit code of 1 is never reported as ENOENT, including with shell: true. Shell built-ins such as dir or echo need shell: true, like with Node's own spawn.
  • Windows: batch files are run by their resolved path, with echo off (#135). They see that path in %0, and no longer print the commands they run, even with @echo on.

Other changes

  • Commands are looked up without which and without changing the process cwd, which also fixes relative commands with a custom cwd in worker threads.
  • Shebangs of short files without a trailing newline are read correctly.

See the changelog for the full list of changes.