[SalesForce] Deploying mdapi and source to org is failing with “Unexpected file found in package directory”

I'm having trouble deploying my mdapi

Steps:

  1. sfdx force:mdapi:retrieve -s -r ./mdapipkg -p
    — This gets the latest version of managed package from our Packaging Org
    — I did not convert to the new source format
  2. In VSCode, I'm now trying to push it to my new PDO and that's where the problems lie. I've tried a handful of commands.

What does "Unexpected file found in package directory" mean here?
I even commented out Dashboards type on my package.xml and still got this error:

Unexpected file… /dashboards/____-meta.xml

**____-MacBook-Pro-2:salesforce-app me$ sfdx force:mdapi:convert --rootdir force-app/main/default --outputdir tmp_convert**
ERROR running force:mdapi:convert:  Unexpected file found in package directory: /Users/me/Dev/____/salesforce-app/force-app/main/default/dashboards/____-meta.xml
**____-MacBook-Pro-2:salesforce-app me$ sfdx force:source:deploy -p force-app/main/default**
ERROR running force:source:deploy:  Unexpected file found in package directory: /Users/me/Dev/_____/salesforce-app/force-app/main/default/dashboards/Reportname-meta.xml
**____-MacBook-Pro-2:salesforce-app me$ sfdx force:mdapi:deploy -d force-app/main/default**
Job ID | 0Af5w00000XORXICA5
MDAPI PROGRESS | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 0/100 Components
The deploy request did not complete within the specified wait time [0 minutes].
To check the status of this deployment, run "sfdx force:mdapi:deploy:report"
**____-MacBook-Pro-2:salesforce-app me$ sfdx force:mdapi:deploy:report**
Job ID | 0Af5w00000XORXICA5
MDAPI PROGRESS | ████████████████████████████████████████ | 0/0 Components

=== Component Failures [1]
TYPE   FILE                 NAME         PROBLEM
─────  ───────────────────  ───────────  ───────────────────────────────────────────────────────────────────────────────────────
Error  default/package.xml  package.xml  The specified package namespace: ____ does not match the namespace for the server:

ERROR running force:mdapi:deploy:report:  The metadata deploy operation failed.

Best Answer

There seems to be a couple of different problems here. First, we need to be clear about which commands are being used to deploy which type of metadata.

Salesforce DX-format source is deployed by sfdx force:source:deploy

Metadata API-format source is deployed by sfdx force:mdapi_deploy.

If converting MDAPI to SFDX format does not succeed, it is unlikely that the resulting force-app directory will be cleanly deployable. Without more information, perhaps in a separate question, I don't see a clear reason why your source conversion failed.

If you're deploying Metadata API-format source, the content of your package.xml should match your src directory, and you shouldn't have any spurious files in src.


The last snippet you shared seems to be the most directly understandable problem:

Error default/package.xml package.xml The specified package namespace: ____ does not match the namespace for the server:

ERROR running force:mdapi:deploy:report: The metadata deploy operation failed.

Your package.xml appears to contain namespaced elements of some kind, while you're deploying to a Developer Edition org that either does not have a namespace (most likely) or has a different namespace.

If your package source contains explicit references to your namespace, you need to build it in a namespaced scratch org, which you can enable by linking your namespace to your Dev Hub.

It's definitely preferable to keep all explicit namespace references out of your metadata because it makes it possible for you to deploy it cleanly to un-namespaced orgs (which should be scratch orgs, not Developer Editions!) during your development process.

More broadly, you should get yourself into a position where you are never retrieving from packaging. Your source repo should be the source of truth for this package. New customizations get deployed to packaging; there should never be changes to retrieve from packaging, and your Git master should always be in a state to deploy cleanly.

Related Topic