Repository navigation
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
spawnandspawnSync, so@types/cross-spawncan be removed. - Only the package itself can be imported, not its internal files, such as
cross-spawn/lib/parse, and the private_parseand_enoentexports 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 leaveerrorunset when there's no error, like Node's, instead of setting it tonull(#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
TypeErrorwith theERR_INVALID_ARG_VALUEcode: 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 asdirorechoneedshell: true, like with Node's ownspawn. - 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
whichand without changing the process cwd, which also fixes relative commands with a customcwdin worker threads. - Shebangs of short files without a trailing newline are read correctly.
See the changelog for the full list of changes.