Sub topic 14
Troubleshooting common project configuration errors
This chapter assumes you can read JSON and have a generated DX project with the Salesforce CLI (sf) installed. It also assumes you know what packageDirectories, .forceignore, and packageAliases do. Most project errors come from a small set of mistakes in sfdx-project.json. Learn to match each message to its cause.
How the CLI reads the file
The CLI looks for sfdx-project.json in the current directory, then in each parent directory. It parses the file as JSON, then checks the package directories on disk. Problems appear in that order: syntax first, then structure, then paths.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Error that the command must run inside a project | Wrong working directory | `cd` into the project folder, or a subfolder of it |
| JSON parse error naming a line or token | Trailing comma, missing quote, or a comment | Fix the syntax. JSON allows no comments |
| No default package directory | No entry has `"default": true` | Mark exactly one directory as default |
| Multiple default package directories | More than one `"default": true` | Keep one |
| Path does not exist | Typo or wrong case in `path` | Match the real folder name |
| Nothing deploys, no error | Files excluded by `.forceignore` | Check the ignore patterns |
| Package alias not found | Dependency name missing from `packageAliases` | Add the alias, or correct the name |
Invalid JSON
A trailing comma is the most common syntax error. This block fails to parse:
{
"packageDirectories": [
{ "path": "force-app", "default": true },
],
"sourceApiVersion": "61.0"
}The comma after the first array item has nothing after it. Remove it. You can check a file quickly with Node.js, if it is installed:
node -e "JSON.parse(require('fs').readFileSync('sfdx-project.json','utf8'))"No output means the JSON is valid.
Default directory and path problems
The CLI needs exactly one default directory when you list more than one. Without it, commands that need a target folder, such as creating a new class, cannot choose where to write.
Paths are relative to the project root and are case-sensitive on Linux and macOS. Force-App works on Windows but fails on a colleague's Mac. Use the exact folder name, and keep the forward slash style in every path.
Silent problems
Some errors give no message at all. If a deploy reports that there is nothing to deploy, check three things:
- The file sits under a directory listed in
packageDirectories. - The
.forceignorefile does not match it. Patterns such as**/profiles/**hide everything under that path. - The folder name matches its metadata type, for example
classesfor Apex classes.
A mismatched sourceApiVersion can also cause confusing failures. If a component uses a feature that the target org's API version lacks, the deploy fails with a metadata error, not a project error. Set the version to one the org supports.
Package and dependency errors
For multi-package projects, check these points:
- Each
packagevalue must have a matching key inpackageAliases. - Each dependency
packagemust also appear inpackageAliases, unless it is another package in the same project. - Place a package after the packages it depends on in
packageDirectories. A dependency listed later causes an ordering error. versionNumbermust have four parts, such as1.0.0.NEXT.
A repeatable debugging routine
- Confirm your location with
pwd, and confirm the file exists withls sfdx-project.json. - Validate the JSON syntax.
- Confirm each
pathexists on disk. - Confirm one default directory.
- Check
.forceignorefor patterns that hide your files. - For packages, check aliases and directory order.
Exercise
A teammate's deploy says "nothing to deploy", but the class file is in force-app/main/default/classes. The JSON is valid and one directory is marked default. Name two things to check next.
Show answer
First, check that force-app is listed as a path in packageDirectories, since only listed directories are read. Second, check .forceignore for a pattern that matches the class file, such as **/classes/**. Also confirm the file name and folder case are exact.
Exercise
A project has core and feature package directories, and feature depends on core. Which one must come first in packageDirectories, and which alias entries must exist?
Show answer
core must come first. packageAliases must contain entries for both core-pkg and feature-pkg.