4

I have a problem installing dependencies from sfdx-project.json. I created a Second Generation Package and generated a new version. I specified dependency as follows:

"dependencies": [
{
    "subscriberPackageVersionId": "04t0V000001Dyaf"
}

But when I try to run

sfdx force:package:install --package 04t...

I get the following error

ERROR: Encountered errors installing the package!,Installation errors:
1) Invalid Upgrade., Details: The package you're installing depends on package 'CloudCraze', version '3.119'. Install package 'CloudCraze' in the target org before you install package '...'.

Shouldn't sfdx install dependencies by itself for Second Generation Packages?

Or dependencies are only used for a successful creation of package versions?

P.S. I know that I can install the dependent package using with preceding sfdx command, but still.

2
  • where in the documentation is this mentioned? (that dependencies for second gen packages are/should automatically be installed, out of curiosity)
    – glls
    Jul 6, 2018 at 12:10
  • You correct, it doesn't. But I haven't found much about this attribute in the documentation, so I decided to ask a question and see maybe I missed something.
    – ytiq
    Jul 6, 2018 at 12:38

3 Answers 3

4

You're right, dependencies are only used by Salesforce to create a new Package Version. If you need to install your Package in a Scratch Org or a Sandbox, you'll need to manually.

As you pointed out, if your package has itself dependencies on other packages, you'll have to list all of them in here and install them in the correct order. This means, if you have 10 dependencies, running 10 times the package install command.

There are at least several plugins that will read your sfdx-project.json file and install all the packages with one command.
For instance we have a sfdx texei:package:dependencies:install command, which was documented in this blog post.

Also, I was at Dreamforce 2022 and attended the Advanced Concepts in Managed 2GP Packaging session, and one slide had this specific note:

Transitive dependencies are not yet supported.

So at least Salesforce is aware and the note can let us think that it will be supported at some point.
You can go to the related Trailblazer Community Chatter Group to ask and try to get more information about the roadmap for this.

1
  • Take a look at this other Q&A for some thoughts around install key handling.
    – Phil W
    Oct 13, 2022 at 9:46
1

This might help:
1. sfdx plugins:install sfdx-dependency-plugin
2. sfdx dependency:order -p 04t.. --maxversion --withrootpackage

You'll get a list of packages versions ids in the right installation order.

Then, using while read ; do...; done you can automatically install package with all its dependencies

1
  • This won't work if the package(s) require an install key, unless you also have a mapping for these too somewhere... a simple alternative to the plugin is to assume dependencies are defined in the correct order within sfdx-project.json, though you still need to figure a way around the install keys.
    – Phil W
    Oct 13, 2022 at 9:40
0

As suggested, I installed the package manually in the stretch org and was able to install the package in the org.

Question - What's the behavior when we install this package on the production and developer org. Does it automatically install the dependent packages? Any information would be very useful for us.

Please suggest.

1
  • it's the same behavior, you need to manage it somehow. I think you still need a third-party plugin for that.
    – ytiq
    Mar 16, 2023 at 0:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .