cross-spawn

A cross-platform drop-in replacement for Node's spawn and spawnSync that fixes Windows-only child_process bugs.

Library
npm
v7.0.6
1,173 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
39 /100 Needs Attention
Development Activity 0
Maintenance 0
Community 68
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 80
Code Quality 78
Innovation 55
Learning Curve 90

cross-spawn solves a long list of platform-specific bugs in Node’s built-in child_process.spawn and spawnSync on Windows: ignored PATHEXT, no shebang support, broken handling of commands containing spaces, failures on posix-style relative paths, and mis-escaped arguments when calling .cmd shims in node_modules/.bin/. It exposes the exact same API as Node’s native spawn functions, so it works as a one-line import swap in existing code.

Internally it resolves the target executable with which, reads the first bytes of the file to detect a shebang line, and — only when a shell is actually required on Windows — rewrites the command and arguments through cmd.exe with careful meta-character escaping. On POSIX platforms it defers straight to Node’s native spawn with no extra overhead.

Because so many CLI tools and build pipelines spawn child processes internally, cross-spawn has become one of the most widely depended-upon packages in the npm ecosystem, quietly making tools that were only ever tested on Linux/macOS actually work when a Windows contributor runs npm test.

What You Get

  • Drop-in spawn and spawn.sync functions with the exact same signature as Node’s child_process module
  • Automatic PATHEXT resolution on Windows so commands without an explicit .exe/.cmd/.bat extension are found correctly
  • Shebang line detection and interpretation for scripts that Windows itself has no native concept of
  • Correct handling of commands and paths containing spaces or posix-style relative segments
  • Safe meta-character escaping when a command must be routed through cmd.exe, including double-escaping for node_modules/.bin shims
  • An ENOENT error emitted consistently across platforms when the target command doesn’t exist, instead of a silent non-zero exit code on Windows

Common Use Cases

  • Powering the child-process invocations inside cross-platform CLI tools and task runners (npm scripts, monorepo tooling, test runners)
  • Spawning linters, compilers, or other locally-installed node_modules/.bin binaries from build scripts without Windows-only failures
  • Running shell commands from Electron or desktop-app main processes that must behave the same on every OS
  • Any library or framework that shells out to git, npm, or other external executables and needs test coverage across platforms

Under The Hood

Architecture

The library has a tiny, layered architecture: index.js is the single public entry point exposing spawn and spawn.sync, both of which funnel every call through lib/parse.js before delegating to Node’s native child_process.spawn/spawnSync. parse.js is the core transformation layer — it normalizes arguments into a parsed object, then on Windows only, detects shebangs by resolving the executable through lib/util/resolveCommand.js (backed by which) and sniffing a #! line via lib/util/readShebang.js, and — only if a shell is actually required — rewrites the command and arguments by escaping meta-characters (lib/util/escape.js) and wrapping everything in a cmd.exe /d /s /c invocation. lib/enoent.js is a separate cross-cutting concern that hooks the spawned child’s emit method to translate a Windows-specific exit-code-1 into a proper ENOENT error, keeping error semantics consistent with POSIX. Every code path ultimately returns to Node’s own spawn implementation, so cross-spawn is architecturally an adapter/transformation layer rather than a reimplementation of process spawning.

Tech Stack

cross-spawn is pure CommonJS JavaScript with no build step and only three runtime dependencies: path-key (resolves the platform-correct PATH variable name), shebang-command (parses an extracted shebang line into a runnable command), and which (PATH-based executable resolution respecting PATHEXT). Development tooling is a coherent, if dated, stack: Jest for tests with coverage, ESLint with eslint-config-moxy, Husky and lint-staged for pre-commit enforcement, commitlint for conventional commits, and standard-version for changelog-driven releases, with CI split across GitHub Actions and AppVeyor so Windows-specific behavior gets dedicated verification.

Code Quality

The test suite is thorough for the library’s scope, covering shebang detection, PATHEXT resolution, argument-escaping edge cases, and ENOENT behavior, backed by a fixtures directory of real executables and shebang scripts rather than pure mocks. Error handling is explicit and deliberate: empty catch blocks appear only where a failed which or chdir attempt is expected and has an established fallback path, not silently swallowed. There is no TypeScript or type annotations anywhere in the codebase; maintainability instead relies on ESLint and a small set of well-named, single-purpose modules.

API Design The defining design decision is that cross-spawn’s public API is intentionally identical to Node’s own child_process.spawn/spawnSync — no new concepts, no new options, just a require swap with zero learning curve. Its value isn’t a novel abstraction but a narrowly-scoped, well-documented Windows compatibility shim for a problem that every cross-platform Node CLI eventually hits.

Used by 17 apps in this directory

TypeScript
96%
MIT

Pi

AI Agents

117,476

An open-source, self-extensible agent harness and coding agent CLI — a modular runtime (agent core, unified multi-provider LLM API, TUI) with no built-in permission system by default, documented containerization patterns for sandboxing instead.

View details
88
Repo Health
73
Technical
73
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 1 weeks ago
TypeScript
97%
AGPL 3.0

Responsively App

Design Tools · Developer Tools

25,464

Preview and interact with your responsive web design across every device size simultaneously — no more manual resizing.

View details
79
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 3 weeks ago
Python
79%
AGPL 3.0

Skyvern

AI Agents · Automation

23,257

Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.

View details
89
Repo Health
82
Technical
70
Dependency
Built with
Python 79%
TypeScript 19%
Updated 6 days ago
TypeScript
98%
Apache 2.0

TinaCMS

CMS

13,845

An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.

View details
92
Repo Health
74
Technical
59
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Python
68%
AGPL 3.0

Tracecat

AI Agents · Automation · Security

3,860

Open-source agentic security automation platform that runs AI agents and durable workflows at scale with sandboxed execution.

View details
89
Repo Health
88
Technical
66
Dependency
Built with
Python 68%
TypeScript 30%
Updated 6 days ago
TypeScript
99%
MIT

Umami

Analytics

39,609

Privacy-first web analytics that respects your users — self-hosted, cookieless, and GDPR compliant out of the box.

View details
95
Repo Health
83
Technical
67
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Automation · Code Editors

28,733

Open-source AI code editor with direct LLM integration and data privacy

View details
44
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 95%
Updated 5 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers