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

Diagnose it: which runtime is actually on PATH?

Runners ship multiple versions of most runtimes and select one through a version manager. When a setup action and a version file disagree, the resulting error is about your code rather than the version.

Terminal
which -a <runtime>
<runtime> --version
echo "PATH=$PATH" | tr ":" "\n" | head -20

# does a version file in the repo disagree with the workflow?
cat .tool-versions .nvmrc .ruby-version .python-version 2>/dev/null

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.

Frequently asked questions

What causes PowerShell "Cannot find path because it does not exist" in CI?
There are 2 common causes: relative path resolved from the wrong working directory and the file was produced by a different step or job. Each step starts in the repo root unless you set working-directory.
How do I fix PowerShell "Cannot find path because it does not exist" in CI?
There are 2 fixes depending on which cause you have: anchor paths to the workspace root and print the working directory and contents to debug. Work through them in order, since the first is the most common.
What does PowerShell "Cannot find path because it does not exist" in CI actually mean?
The step fails with ItemNotFoundException naming the path.
How do I stop PowerShell "Cannot find path because it does not exist" in CI happening again?
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

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card