Node.js "cross-env: command not found" in CI
A script uses cross-env to set environment variables portably, but the binary is missing in CI. With dev deps pruned (or never installed), the shell cannot find cross-env and exits 127.
What this error means
A script that starts with cross-env NODE_ENV=production ... fails with cross-env: command not found and exit code 127. The same script works locally where dev deps are present.
> build
> cross-env NODE_ENV=production vite build
sh: cross-env: command not found
npm ERR! code 127Common causes
devDependencies pruned in CI
cross-env is a devDependency. A --omit=dev install removes it, so the build script cannot find the binary.
cross-env not declared at all
The script relies on cross-env but it was never added to package.json, so it is absent on a clean install.
How to fix it
Install cross-env and keep dev deps for builds
Add cross-env as a devDependency and run a full install in build jobs.
npm install -D cross-env
# build job uses a full install
npm ciSet env without cross-env on POSIX runners
On Linux CI you can set env inline and drop the dependency entirely if Windows support is not needed.
NODE_ENV=production vite buildHow to prevent it
- Keep devDependencies installed for build jobs.
- Declare every CLI a script uses in package.json.
- Drop cross-env where only POSIX runners run the script.