Salesforce "Cannot read property accessToken" in CI
The CLI loaded an org connection whose auth fields are undefined, then dereferenced accessToken on it. The org was never authorized in this environment, or its cached auth file is empty or corrupt.
What this error means
A command crashes with "Cannot read property 'accessToken' of undefined" or "Cannot read properties of undefined (reading 'accessToken')" instead of a clean auth error.
TypeError: Cannot read properties of undefined (reading 'accessToken')Common causes
No valid auth record for the target org
The alias resolves to an org with no usable token, so the connection object lacks accessToken. This follows a failed or skipped login.
A stale or corrupted auth cache
A partially written auth file (interrupted login, restored cache) leaves the org record without credentials.
How to fix it
Re-authenticate cleanly
- Log out the alias to clear any partial record.
- Run the JWT or auth-URL login again in this job.
- Confirm
sf org display --target-org <alias>returns an access token.
sf org logout --target-org ci-org --no-prompt || true
sf org login jwt --alias ci-org ...
sf org display --target-org ci-orgDo not cache the CLI auth directory blindly
If you cache ~/.sfdx/~/.sf across runs, a stale entry can yield an empty token. Prefer re-authenticating each run over restoring auth caches.
How to prevent it
- Authenticate fresh in each job rather than caching auth state.
- Verify the org with
sf org displaybefore commands that need a token. - Keep the CLI updated so auth-record handling stays current.