37

When I run composer install, it will install all my "require" and the "require" of the other package.

My composer.json

{
    "name": "my_app",
    "require": {
        "some/package": "0.0.0"
    }
}

The "child" dependency

{
    "name": "some/package",
    "require": {
        "zendframework/zend-mail": "2.4.*@dev",
        "soundasleep/html2text": "~0.2",
        "mpdf/mpdf": "6.0.0",
        "endroid/qrcode": "1.*@dev"
    }
}

I know that it's possible ignore the php extensions, but what about these second require package?

5 Answers 5

64

You can ignore packages to be downloaded with the replace property of your composer.json: https://getcomposer.org/doc/04-schema.md#replace

That way you tell composer, that you take or took care of that package's content on your own.

This can help you to ignore a package your are sure you do not need, but it is kind of hacky. So be aware some things (like tests) might break. A better approach would be to request a patch from the maintainer of the original package to make the requirements optional (via the suggest property).

edit:
Example for "disabling" the requirement to zendframework/zend-mail:

{
    "name": "my_app",
    "require": {
        "some/package": "0.0.0"
    },
    "replace": {
        "zendframework/zend-mail": "*"
    }
}
4
  • 1
    I don't understand from the documentation that how I can prevent a child dependency. Can you please give an example? Commented Nov 7, 2017 at 19:14
  • 1
    @Bunyamin I added an example to my post.
    – derhasi
    Commented Nov 22, 2017 at 13:35
  • 1
    If any of your dependencies needs a specific version, you need to set your version of the package to the same "version": "3.1.4", e.g under "name": "some/package". You are basically replacing that package with the current composer.json itself. Commented Apr 3, 2018 at 11:47
  • Is the suggest approach really better? A default usage of a package would probably cause an error. I'd prefer the replace appraoch, where one explicitly ignores a dependency, knowing what she or he is doing.
    – robsch
    Commented Apr 4, 2023 at 7:23
29

I know that it's possible ignore the php extensions, but what about these second require package?

Yes, you can use --ignore-platform-reqs to ignore php, hhvm, lib-* and ext-* platform requirements and force the installation, even if the local machine does not fulfill these.

But, i'm not sure were you are heading with your question. What's the use-case for requiring a package without its dependencies in your application? Isn't this the main reason to use Composer?

No, its not possible, unless you are looking for require --no-update, which disables the automatic update of the dependencies. Please take a look at the CLI options for require and install.

3
  • The package that I'm using have a lot of "libs" which I use some. So those no used libs require things that I don't need, but I don't want just copy the files and loose the next updates.
    – Pablo
    Commented Jan 6, 2016 at 19:49
  • 1
    I would suggest to approach this differently: fetch everything, also the child dependencies, build your application and use only some of these dependencies and then when you build a release package of your stable application, delete the unused libraries before or ignore them during packaging. That allows to work with all dependencies during development and but shrinks stuff to the minimum for deployment. Commented Jan 6, 2016 at 20:07
  • 1
    Right! Thank you for the advice.
    – Pablo
    Commented Jan 6, 2016 at 22:06
5

One more way to solve it:

  1. Clone package to your repository and fix dependencies
  2. In your composer.json add your repository:
"repositories": [
    { "type": "git", "url": "https://github.com/zhovtyj/mailchimp-laravel" }
],
"require": {
    "php": "^7.1.3",
    ***
    "skovmand/mailchimp-laravel": "dev-master",
},
2

Another option could be to modify the composer.json of the child package and to remove the required dependencies. Then you could host the zip file and add reference it by adding an extra repository for your main package.

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "dr-que/x-y",
            "version": "master",
            "dist": {
                "type": "zip",
                "url": "http://xyplot.drque.net/Downloads/XY_Plot-1.4.zip",
                "reference": "master"
            },
            "autoload": {
                "classmap": ["."]
            }
        }
    }
]

Then in your require section, add your selected name as follows.

"require": {
    "dr-que/x-y": "dev-master"
}

For the autoload, I just copied the same autoload section of the child package.

The original solution can be found here

1

Just Use

 composer install --ignore-platform-reqs
2
  • 6
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: stackoverflow.com/help/how-to-answer . Good luck 🙂
    – nima
    Commented Oct 3, 2021 at 22:09
  • --ignore-platform-reqs requires an argument so, this command will fail with an error. Commented Aug 7, 2023 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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