canirequire › ESM-only › cross-env
Is cross-env ESM-only? Can you require() it?
Run scripts that set and use environment variables across platforms
Last verified Sep 9, 2026 against cross-env@10.1.0. JSON
ESM-only ESM-only since 10.0.0 — last CommonJS version is 7.0.3
cross-env dropped its CommonJS build in 10.0.0 (July 2025). The last version you can require() on every Node.js version, including 18 and older, is 7.0.3, published Dec 1, 2020.
require("cross-env") failed in our probe on Node.js 20+ as well. See the runtime matrix below for the exact error.
cross-env@10.1.0 declares engines ">=20", so Node.js 18 is outside its supported range regardless of module format.
Does cross-env@10.1.0 actually load? Runtime test results
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 | ✗ failsERR_PACKAGE_PATH_NOT_EXPORTED | ✓ works |
| Node.js 20 | ✗ failsERR_PACKAGE_PATH_NOT_EXPORTED | ✓ works |
| Node.js 22 | ✗ failsERR_PACKAGE_PATH_NOT_EXPORTED | ✓ works |
| Node.js 24 | ✗ failsERR_PACKAGE_PATH_NOT_EXPORTED | ✓ works |
| Node.js 26 | ✗ failsERR_PACKAGE_PATH_NOT_EXPORTED | ✓ works |
| Bun 1.4 | ✗ failserror: Cannot find package 'cross-env' from '/Users/boat/Projects/top-seo/data/probe-work/cross-env/req.cjs' | ✓ works |
How to import cross-env
ES modules (import)
import crossEnv from "cross-env";CommonJS (require)
// Node.js 20.19+ / 22.12+ / newer (package has no top-level await):
const crossEnv = require("cross-env");
// Any Node.js version:
const crossEnv = await import("cross-env");
// Or pin the last CommonJS release:
// npm install cross-env@7.0.3Module 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 you can require() on every Node.js version, including 18 and older, is 7.0.3, published Dec 1, 2020.
Which version of cross-env still supports CommonJS / require()?
7.0.3 is the last version of cross-env with a CommonJS build. 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?
Use a dynamic import: const mod = await import("cross-env"). On Node.js 20.19+, 22.12+ and newer, a plain require("cross-env") also works for ESM packages that do not use top-level await. Alternatively pin cross-env@7.0.3.
Does cross-env work in Bun?
Yes. import "cross-env" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does cross-env ship TypeScript types?
Yes. cross-env bundles its own type declarations; no @types package is needed.
Links
Other esm-only packages
- ansi-styles 7.0.0last CJS
5.2.0 - strip-ansi 7.2.0last CJS
6.0.1 - commander 15.0.0last CJS
14.0.3 - supports-color 11.0.0last CJS
8.1.1 - chalk 6.0.0last CJS
4.1.2 - tslib 2.8.1last CJS
2.5.2 - string-width 8.2.2last CJS
4.2.3 - ansi-regex 6.3.0last CJS
5.0.1
Similar popularity
- @smithy/querystring-parser 4.5.2CommonJS
- validator 13.15.35CommonJS
- make-fetch-happen 16.0.1CommonJS
- http-proxy-middleware 4.2.0ESM-only
- query-string 9.5.1ESM-only
- nodemailer 10.0.1Dual
- redux-thunk 3.1.0Dual
- jest-environment-jsdom 30.5.1Dual