Skip to content
Latchkey

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.

node
> build
> cross-env NODE_ENV=production vite build

sh: cross-env: command not found
npm ERR! code 127

Common 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.

Terminal
npm install -D cross-env
# build job uses a full install
npm ci

Set 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.

workflow
NODE_ENV=production vite build

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →