Search code examples
phplaraveldompdf

Cannot install barryvdh/laravel-dompdf


I could not install barryvdh/laravel-dompdf using composer require barryvdh/laravel-dompdf.

The error I got was:

[Invalid argument exception] Could not find a matching version of barryvdh/laravel-dompdf. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (dev).

So in order to fix the error, I included barryvdh/laravel-dompdf: master@dev in composer.json and did a composer update. This time it gave me the error:

The requested package barryvdh/laravel-dompdf could not be found in any version. there may be a typo in the package name

Below is my composer.json:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "^1.0",
        "barryvdh/laravel-dompdf": "master@dev"
    },
    "repositories":
    [
        {
          "type": "composer",
          "url": "https:\/\/www.phpclasses.org\/"
        },
        {
          "packagist": false
        }
    ],
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "app/includes",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

What do you think I am missing here?


Solution

  • Usually, it is advisable not to edit composer.json directly when installing third-party packages. You can remove the line "barryvdh/laravel-dompdf": "master@dev" from your file, and run this command from your project root directory instead:

    composer require barryvdh/laravel-dompdf
    

    It installs the latest stable third-party package and automatically updates both composer.json and composer.lock files.

    UPDATE: To solve the problem with your composer.jsonfile, change the repositories key to this:

    "repositories" : 
    [
        {
            "type": "composer",
            "url": "https://packagist.org"
        },
        {
            "packagist": false
        }
    ]