GitHub Actions "Matrix ... must define at least one vector" in CI
A matrix needs at least one base axis (a key with a list of values). Providing only include/exclude, or an axis whose dynamic value expanded to an empty list, leaves no vector to expand.
What this error means
The run fails with "Invalid workflow file" and "Matrix ... must define at least one vector", or the matrixed job produces zero runs.
GitHub Actions
Invalid workflow file: .github/workflows/ci.yml
(Line: 9, Col: 7): Matrix must define at least one vectorCommon causes
Only include/exclude, no base axis
A matrix with just include: and no list-valued key has no vector to start from.
A dynamic axis expanded to empty
An axis built from fromJSON(...) resolved to [], so there is nothing to combine.
How to fix it
Add a base axis with at least one value
- Define a list-valued key under
matrix. - Keep
include/excludeas adjustments, not the only content. - Re-run the workflow.
.github/workflows/ci.yml
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
node: 20Guard a dynamic matrix against empty
Default the generated axis to a non-empty list so it always has a vector.
bash
echo "list=${list:-[\"ubuntu-latest\"]}" >> "$GITHUB_OUTPUT"How to prevent it
- Always include at least one base axis in a matrix.
- Default dynamic axes to a non-empty list.
- Echo a generated matrix before consuming it.
Related guides
GitHub Actions "fromJSON ... Unable to parse" in CIFix GitHub Actions "Unable to parse" from fromJSON in CI - the string handed to fromJSON was not valid JSON,…
GitHub Actions "mapping values are not allowed in this context" in CIFix GitHub Actions "while scanning ... mapping values are not allowed in this context" in CI - a stray colon…
GitHub Actions "could not find expected ':'" YAML error in CIFix GitHub Actions "could not find expected ':'" in CI - the YAML scanner reached the end of a key without th…