API Reference

cross-env

Set environment variables cross-platform so scripts work on Windows, macOS, and Linux with one syntax.

Official Documentation ↗
CompatibilityThis documentation covers version v7. Check the official docs for the latest API surface.

Installation

npmnpm install --save-dev cross-env

Methods

cross-env normalizes environment variable assignment so package.json scripts do not need platform variants.

Key Features

  • One syntax on all platforms
  • Multiple variable assignments in one command
  • cross-env-shell for commands needing a shell

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/kentcdodds/cross-env@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:02.260Z.

FAQ

Why not just write KEY=value in npm scripts?
That syntax fails on Windows cmd, which needs set KEY=value. cross-env abstracts the difference so one script works everywhere.
When do I need cross-env-shell?
Only when the command contains shell operators such as && or pipes. Plain commands work with the regular cross-env binary.
Can I set an empty value?
Yes. Assign KEY= with nothing after the equals sign to define an empty variable, which some tools treat as unset.