# Is cross-env ESM-only? Can you require() it?

> cross-env@10.1.0 is ESM-only. ESM-only since 10.0.0 — last CommonJS version is 7.0.3.

Run scripts that set and use environment variables across platforms

Last verified Sep 9, 2026 against cross-env@10.1.0.

cross-env dropped its CommonJS build in 10.0.0 (July 2025). The last version with a plain require()-able CommonJS entry is 7.0.3, published Dec 1, 2020; it declares support for Node.js >=10.14.

require("cross-env") failed in our probe on Node.js 20+ as well; see the runtime table for the error before relying on it. Node.js 18 has no require(esm), and cross-env@10.1.0 declares Node.js >=20, so 18 is outside its supported range anyway.

cross-env@10.1.0 declares engines ">=20", so Node.js 18 is outside its supported range regardless of module format.

## What to do

1. require("cross-env") failed in our probe on Node.js 20+ as well; see the runtime table for the error before relying on it.
2. From a CommonJS file, use a dynamic import inside an async function: const crossEnv = await import("cross-env"). That works on every Node.js version the package supports (>=20).
3. If you need a synchronous require() or run Node.js 18: npm install cross-env@7.0.3, the last CommonJS release (published Dec 1, 2020); it declares Node.js >=10.14.
4. cross-env@10.1.0 declares engines ">=20", so Node.js 18 is unsupported regardless: upgrade Node.js or pin an older release.
5. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 10.1.0 (Sep 29, 2025)
- Module format: ESM-only
- Last CommonJS version: 7.0.3
- ESM-only since: 10.0.0 (Jul 25, 2025)
- TypeScript types: bundled
- Node engines: >=20
- Weekly downloads: 22.2M
- License: MIT

## Runtime test results for cross-env@10.1.0

Installed and executed on Sep 9, 2026 with require("cross-env") from a CommonJS file and import "cross-env" from an ES module.

| Runtime | require("cross-env") | import "cross-env" |
|---|---|---|
| Node.js 18 | fails (ERR_PACKAGE_PATH_NOT_EXPORTED) | works |
| Node.js 20 | fails (ERR_PACKAGE_PATH_NOT_EXPORTED) | works |
| Node.js 22 | fails (ERR_PACKAGE_PATH_NOT_EXPORTED) | works |
| Node.js 24 | fails (ERR_PACKAGE_PATH_NOT_EXPORTED) | works |
| Node.js 26 | fails (ERR_PACKAGE_PATH_NOT_EXPORTED) | works |
| Bun 1.4.0 | fails (Error) | works |

## How to import cross-env

ES modules:

```js
import * as crossEnv from "cross-env";
```

Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.

CommonJS:

```js
// require("cross-env") failed in our probe on Node.js 20.19+, 22.12+ and newer as well (ERR_PACKAGE_PATH_NOT_EXPORTED); see the runtime table.

// Any Node.js version the package supports (>=20), from an async function:
async function main() {
  const crossEnv = await import("cross-env");
}

// Or pin the last CommonJS release (declares Node.js >=10.14):
// npm install cross-env@7.0.3
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (48 versions; the newest 48 shown).

| Versions | Format | First published |
|---|---|---|
| 10.0.0 – 10.1.0 | ESM-only | Jul 25, 2025 |
| 1.0.0 – 7.0.3 | CommonJS | Oct 1, 2015 |

## Frequently asked

**Is cross-env ESM-only?**

cross-env@10.1.0 is ESM-only. cross-env dropped its CommonJS build in 10.0.0 (July 2025). The last version with a plain require()-able CommonJS entry is 7.0.3, published Dec 1, 2020; it declares support for Node.js >=10.14.

**Which version of cross-env still supports CommonJS / require()?**

7.0.3 is the last version of cross-env with a CommonJS build; it declares Node.js >=10.14. Install it with "npm install cross-env@7.0.3". Every version from 10.0.0 on is ESM-only.

**How do I use cross-env from a CommonJS file?**

From a CommonJS file, use a dynamic import inside an async function: const crossEnv = await import("cross-env"). That works on every Node.js version the package supports (>=20). require("cross-env") failed in our probe on Node.js 20+ as well; see the runtime table for the error before relying on it. Alternatively pin cross-env@7.0.3 (declares Node.js >=10.14).

**Does cross-env work in Bun?**

Yes. import "cross-env" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does cross-env ship TypeScript types?**

Yes. cross-env bundles its own type declarations; no @types package is needed.

## Links

- [cross-env on npm](https://www.npmjs.com/package/cross-env)
- [Source repository](https://github.com/kentcdodds/cross-env)
- [HTML version](https://canirequire.com/package/cross-env/)
- [JSON version](https://canirequire.com/package/cross-env.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
