Skip to content
Latchkey

Newman "unable to load environment" file in CI

Newman could not load the environment file passed with -e, so none of its variables (baseUrl, token) are defined. Requests then resolve to broken URLs like {{baseUrl}}/user and fail.

What this error means

Newman prints "unable to load an environment file" or requests error with an unresolved {{baseUrl}} in the URL. The environment path is wrong or the JSON is malformed.

newman
error: unable to load environment
  ENOENT: no such file or directory, open 'ci.postman_environment.json'

Common causes

The environment path is wrong

The -e path does not resolve from the runner working directory, so Newman finds no environment and variables stay undefined.

The environment JSON is invalid

A hand-edited environment export has a syntax error or is not a Postman environment schema, so Newman refuses to load it.

How to fix it

Pass a valid environment path

  1. Confirm the environment file exists at the path you pass to -e.
  2. Validate the JSON parses and is a Postman environment export.
  3. Re-run so {{baseUrl}} and other variables resolve.
Terminal
newman run collection.json -e tests/postman/ci.postman_environment.json

Set variables inline when there is no env file

If you do not ship an environment file in CI, supply the variables directly with --env-var.

.github/workflows/ci.yml
newman run collection.json \
  --env-var "baseUrl=http://localhost:3000" \
  --env-var "token=${{ secrets.API_TOKEN }}"

How to prevent it

  • Commit the CI environment file and reference it by full path.
  • Validate environment JSON in a lint step before the run.
  • Prefer --env-var for secrets so tokens are injected, not committed.

Related guides

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