7

Error deploying or retrieving source: The file or directory that you tried to deploy or retrieve isn't in a package directory that's specified in your sfdx-project.json file. Add this location to your "packageDirectories" value, or deploy or retrieve a different file or directory. For details about sfdx-project.json, see: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm

Please help me.

2
  • 2
    All answers here are legit, I just wanted to mention that you might just simply have opened the wrong root folder, for example, I faced this issue by opening a repo from within Github Desktop in VSCode (Github Desktop gives you the option to open a repo in your default code editor). To fix it, I simply closed the folder in vscode and went to File->Open and just open the repo this way and everything is back to normal now, hope it helps. Cheers!
    – Bahman.A
    May 7, 2020 at 16:01
  • This answer is really nice as well: salesforce.stackexchange.com/questions/245143/…
    – Bahman.A
    May 7, 2020 at 16:03

12 Answers 12

26

If you are reaching this question in July of 2022, there is an issue with the most recent Salesforce CLI Integration Extension for VS Code on Windows.

To resolve, go to your extensions, go to Salesforce CLI Integration, click the drop-down next to Uninstall, and click "Install another version". Install the previous version (55.3.0)

Here is the Github link to the known issue if you want to follow it for updates.

Update 2022-07-11: As mentioned by @Swetha and @SFDC Dev 27 in comments, upgrading Salesforce CLI to v55.4.1 resolves this issue

3
  • 6
    I'm honestly grateful you're pointing this out, because I've suffered from this problem all day today and was already wondering. You could improve this answer significantly by referring to anything on Github or elsewhere that makes you think this is not just a problem of "our" configuration ;-) Jul 8, 2022 at 16:42
  • 4
    As a fix, v55.4.1 of the Salesforce Extension for VS Code has been published. See the release notes here: github.com/forcedotcom/salesforcedx-vscode/releases/tag/v55.4.1
    – Swetha
    Jul 9, 2022 at 7:08
  • 2
    decreasing the Salesforce Extension worked for me. And now I tested with the 55.4.1 and that also works. Thanks a LOT @EmilyHolden you saved a lot of hours for many of us Jul 11, 2022 at 7:22
2

I was getting the same error on retrieving the components from org. So i went to the package.xml file and right click > SFDX:Retreive Source in Manifest from org and it worked. Then you can try the SFDX: Deploy this source to Org.

2

I too had the same problem. I got the error when i right click and Deploy to Source Org.

Error deploying or retrieving source: The file or directory that you tried to deploy or retrieve isn't in a package directory that's specified in your sfdx-project.json file. Add this location to your "packageDirectories" value, or deploy or retrieve a different file or directory. For details about sfdx-project.json, see: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm

But i was able to deploy with the following command.

sfdx force:source:deploy --sourcepath .\force-app\main\default\classes\testFirstClass.cls --json --loglevel trace

Regards, Chandra

1

The folder in which you have/want to retrieve source code, you need to specify it in "sfdx-project.json" file. Also, this path should be relative to the directory of the project.

enter image description here

By default, all source code/metadata is stored in a folder called "force-app".

Currently, my sfdx-project.json file looks like:

{
  "packageDirectories": [
    {
      "path": "force-app", /* this is my relative path */
      "default": true
    }
  ],
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "45.0"
}

Just replace force-app with a relative path to your directory.

10
  • 1
    Can you please describe how can we give relative path considering your case? Apr 26, 2019 at 8:04
  • 1
    @change_is_necessity I have added a comment "this is my relative path" in answer. Apr 26, 2019 at 9:36
  • I have exactly the same settings but still I am getting the same error even on newly created project I am getting the same error
    – gs650x
    Jul 8, 2022 at 12:12
  • 1
    I never had this issue and I have like 10 SFDX projects. It just stopped working today. I was not abe to get it working yet, but I am wondering why it broke suddenly. Is it any VSC update? Jul 8, 2022 at 12:59
  • 1
    Same issue, It suddenly stopped working...
    – Srujan
    Jul 8, 2022 at 13:19
1

🚨 As Swetha mentioned on her comment in the top answer, the extension has been fixed as of 2 days ago as part of v55.4.1 of the Salesforce Extension for VS Code 🚨

If you're still getting the error navigate to the Extensions button and click reload on one of the Salesforce extensions:

See this image for instructions on reloading VS Code Extensions

0

Please use the command Like Below:

sfdx force:source:deploy --sourcepath '' --json --loglevel trace

ex: sfdx force:source:deploy --sourcepath 'C:\Users\madhu\Desktop\TestProject\force-app\main\default\lwc\PatientDetails' --json --loglevel trace

0

Here in 2023 w/this issue. I'm guessing there are a variety of ways to get stuck/blocked by this error but in case it helps anyone in a similar situation ...

Issue:

One of my previous "SFDX: Retrieve Source from Org" calls pulled down a few files into /profiles and /applications folder. The existence of these files was producing the following errors:

Error deploying or retrieving source: The file or directory that you tried to deploy or retrieve isn't in a package directory that's specified in your sfdx-project.json file. Add this location to your "packageDirectories" value, or deploy or retrieve a different file or directory.

and

Cannot create a new component with the namespace: standard. Only components in the same namespace as the organization can be created...

Solution

Deleting the above-mentioned directories resolved the issue** and my SFDX: Deploy Source to Org (or command line equivalent) FINALLY started working again.

Notes:

  • I realize I did not actually fix whatever the issue was - more like hacked my way out of it - maybe even just temporarily - but at least it's gone now and I can get back to work.
  • I tried the downgrade/reload of the SFDX CLI extension - didn't change anything. I also tried deploying from the command line and from the VS Code command palette - both failed.
  • Also I did not have any manifest/package XML file before all this mess - everything was working fine w/out it. Still don't have one. Project was created with the SFDX: Create new project / Standard command FWIW.
0

SOLVED This will solve for sure,

to retrieve multiple Unlocked packages to local system we need to add multiple path locations to Sfdx.JSON file. this make DX to look at these paths and retriev/Deploye without any error.

Your sfdx-project.json should looks like this.

{
  "packageDirectories": [
      { "path" : "force-app" ,"default": true }, 
      { "path" : "./ItemsToApprove" }
  ],
  "name": "Sandbox-Umesh",
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "56.0",
  "pushPackageDirectoriesSequentially": true
}

documentation given here

in my case "path" : "./ItemsToApprove" , where ItemsToApprove is unlocked Package that I want retrieve/Updae

Let me know if this solves

I have answered here also : Link to My Answer

-1

Silly but in my case I was right clicking on the package.json on the root folder instead of manifest\package.xml

-1

I just modified "path", and it's worked in my case. enter image description here

-1

I also received the same error. I solved it by moving to file in force-app/main/default folder

-1

Clicking on manifest\package.xml worked for me I was incorrectly right-clicking on the manifest folder

Not the answer you're looking for? Browse other questions tagged or ask your own question.