Skip to content
Latchkey

PowerShell "Cannot find path because it does not exist" in CI

A cmdlet such as Get-Item, Copy-Item, or Set-Location was handed a path that does not resolve on the runner. The path is usually relative to the wrong directory or uses the wrong separator.

What this error means

The step fails with ItemNotFoundException naming the path. It is deterministic, and the path it prints is often subtly different from what you expect once the runner working directory is taken into account.

powershell
Get-Content : Cannot find path 'C:\actions-runner\_work\repo\repo\dist\app.js'
because it does not exist.
At line:1 char:1
+ Get-Content dist/app.js
    + CategoryInfo          : ObjectNotFound: (...dist\app.js:String) [], ItemNotFoundException
    + FullyQualifiedErrorId : GetContentReaderPathNotFound

Common causes

Relative path resolved from the wrong working directory

Each step starts in the repo root unless you set working-directory. A path relative to a subfolder fails because PowerShell joins it onto a different base.

The file was produced by a different step or job

Artifacts written in one job do not exist in another unless uploaded and downloaded. Referencing a build output that this job never produced gives a missing path.

How to fix it

Anchor paths to the workspace root

Build absolute paths from a known root with Join-Path instead of relying on the current directory.

powershell
$root = $env:GITHUB_WORKSPACE
$dist = Join-Path $root 'dist/app.js'
if (-not (Test-Path $dist)) { throw "missing: $dist" }
Get-Content $dist

Print the working directory and contents to debug

Confirm where the step actually runs and what is on disk before reading the file.

powershell
Get-Location
Get-ChildItem -Force

How to prevent it

  • Use Join-Path with $env:GITHUB_WORKSPACE for any file you read, and verify build outputs exist with Test-Path before consuming them.

Related guides

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