[SalesForce] How to specify managed package dependency

My unlocked package (DX project) depends on a package from the app store, so a managed package.

How do I correctly specify this in the project file? During development I've manually installed the package in every scratch org, but it fails during package:version:create. I guess it is the dependency that fails…

Best Answer

On the commandline, find the package ID of the managed package you depend on. You can list all packages like this:

sfdx force:package:installed:list -u ORG_ALIAS_EG_PROD_OR_SANDBOX

Then you'd just add this to the dependency section (the Id starting with 04t...) e.g.

"dependencies": [
    {
       "package": "PACKAGE_ID_HERE"
    }
],

I've also seen examples where you'd use package aliases, but it seems to do the same:

"dependencies": [
    {
       "package": "some_alias_here"
    }
],

...
packageAliases : {
    "some_alias_here":"04t........."
}

Anyway, even with all the dependencies correct, remember that, at the time of writing (Sep'18), unlocked packages is still in beta so not everything may work, at least id didn't for me.