Ocramius / PackageVersions

:package: Composer addon to efficiently get installed packages' version numbers
MIT License
3.22k stars 67 forks source link

No lockfile found, unable to read locked packages #109

Closed Einenlum closed 5 years ago

Einenlum commented 5 years ago

Hi. When I init a composer project with no dependencies and try to dump-autoload, I get this error and it seems it's involving this package:

➜  login composer dump-autoload -vvv
Reading ./composer.json
Loading config file ./composer.json
Checked CA file /etc/ca-certificates/extracted/tls-ca-bundle.pem: valid
Executing command (/home/einenlum/Prog/einenlum/login): git branch --no-color --no-abbrev -v
Executing command (/home/einenlum/Prog/einenlum/login): git describe --exact-match --tags
Executing command (/home/einenlum/Prog/einenlum/login): git log --pretty="%H" -n1 HEAD
Executing command (/home/einenlum/Prog/einenlum/login): hg branch
Executing command (/home/einenlum/Prog/einenlum/login): fossil branch list
Executing command (/home/einenlum/Prog/einenlum/login): fossil tag list
Executing command (/home/einenlum/Prog/einenlum/login): svn info --xml
Reading /home/einenlum/.config/composer/composer.json
Loading config file /home/einenlum/.config/composer/composer.json
Reading /home/einenlum/.config/composer/vendor/composer/installed.json
Loading plugin PackageVersions\Installer
Running 1.8.6 (2019-06-11 15:03:05) with PHP 7.3.7 on Linux / 5.1.19-1-MANJARO
Generating autoload files

  [LogicException]                                   
  No lockfile found. Unable to read locked packages  

Exception trace:
 () at phar:///usr/local/bin/composer/src/Composer/Package/Locker.php:266
 Composer\Package\Locker->getLockData() at /home/einenlum/.config/composer/vendor/ocramius/package-versions/src/PackageVersions/Installer.php:188
 PackageVersions\Installer::getVersions() at n/a:n/a
 iterator_to_array() at /home/einenlum/.config/composer/vendor/ocramius/package-versions/src/PackageVersions/Installer.php:106
 PackageVersions\Installer::dumpVersionsClass() at n/a:n/a
 call_user_func() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:176
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:96
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php:312
 Composer\Autoload\AutoloadGenerator->dump() at phar:///usr/local/bin/composer/src/Composer/Command/DumpAutoloadCommand.php:78
 Composer\Command\DumpAutoloadCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:258
 Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:104
 Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:61
 require() at /usr/local/bin/composer:24

dump-autoload [--no-scripts] [-o|--optimize] [-a|--classmap-authoritative] [--apcu] [--no-dev]

Here is the composer.json:

{
    "name": "einenlum/login",
    "authors": [
        {
            "name": "Yann Rabiller",
            "email": "yann.rabiller@fortrabbit.com"
        }
    ],
    "require": {}
}

Details about the installed version of ocramius/package-versions:

➜  login composer global show ocramius/package-versions
Changed current directory to /home/einenlum/.config/composer
name     : ocramius/package-versions
descrip. : Composer plugin that provides efficient querying for installed package versions (no runtime IO)
keywords : 
versions : * 1.5.1
type     : composer-plugin
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source   : [git] https://github.com/Ocramius/PackageVersions.git 1d32342b8c1eb27353c8887c366147b4c2da673c
dist     : [zip] https://api.github.com/repos/Ocramius/PackageVersions/zipball/1d32342b8c1eb27353c8887c366147b4c2da673c 1d32342b8c1eb27353c8887c366147b4c2da673c
path     : /home/einenlum/.config/composer/vendor/ocramius/package-versions
names    : ocramius/package-versions

autoload
psr-4
PackageVersions\ => src/PackageVersions

requires
composer-plugin-api ^1.0.0
php ^7.3.0

requires (dev)
composer/composer ^1.8.6
doctrine/coding-standard ^6.0.0
ext-zip *
infection/infection ^0.13.4
phpunit/phpunit ^8.2.5
vimeo/psalm ^3.4.9

Creating this issue after this one was closed in the composer/composer repository.

Ocramius commented 5 years ago

Hmm, interesting: never thought of the use-case of composer dump-autoload without composer install.

Would you consider sending a patch stating that composer install is required first?

Einenlum commented 5 years ago

Doing a composer install before does not solve the problem because composer install does not work either :/.

➜  login composer install -vvv
Reading ./composer.json
Loading config file ./composer.json
Checked CA file /etc/ca-certificates/extracted/tls-ca-bundle.pem: valid
Executing command (/tmp/login): git branch --no-color --no-abbrev -v
Executing command (/tmp/login): git describe --exact-match --tags
Executing command (/tmp/login): git log --pretty="%H" -n1 HEAD
Executing command (/tmp/login): hg branch
Executing command (/tmp/login): fossil branch list
Executing command (/tmp/login): fossil tag list
Executing command (/tmp/login): svn info --xml
Reading /home/einenlum/.config/composer/composer.json
Loading config file /home/einenlum/.config/composer/composer.json
Reading /tmp/login/vendor/composer/installed.json
Reading /home/einenlum/.config/composer/vendor/composer/installed.json
Loading plugin PackageVersions\Installer
Running 1.8.6 (2019-06-11 15:03:05) with PHP 7.3.7 on Linux / 5.1.19-1-MANJARO
Loading composer repositories with package information
Downloading https://repo.packagist.org/packages.json
Writing /home/einenlum/.cache/composer/repo/https---repo.packagist.org/packages.json into cache
Updating dependencies (including require-dev)
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2013.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2014.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2015.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2016.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2017.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2018.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2018-10.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2019-01.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2019-04.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-2019-07.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-archived.json from cache
Reading /home/einenlum/.cache/composer/repo/https---repo.packagist.org/p-provider-latest.json from cache
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.000 seconds
Analyzed 48 packages to resolve dependencies
Analyzed 48 rules to resolve dependencies
Nothing to install or update
Reading /tmp/login/vendor/composer/installed.json
Generating autoload files

  [LogicException]                                   
  No lockfile found. Unable to read locked packages  

Exception trace:
 () at phar:///usr/local/bin/composer/src/Composer/Package/Locker.php:266
 Composer\Package\Locker->getLockData() at /home/einenlum/.config/composer/vendor/ocramius/package-versions/src/PackageVersions/Installer.php:188
 PackageVersions\Installer::getVersions() at n/a:n/a
 iterator_to_array() at /home/einenlum/.config/composer/vendor/ocramius/package-versions/src/PackageVersions/Installer.php:106
 PackageVersions\Installer::dumpVersionsClass() at n/a:n/a
 call_user_func() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:176
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:96
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php:312
 Composer\Autoload\AutoloadGenerator->dump() at phar:///usr/local/bin/composer/src/Composer/Installer.php:304
 Composer\Installer->run() at phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php:122
 Composer\Command\InstallCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:258
 Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:104
 Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:61
 require() at /usr/local/bin/composer:24

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...
Ocramius commented 5 years ago

Yeah, but why is that autoload generator being started before composer.lock is there?

Einenlum commented 5 years ago

I have no clue.

Ocramius commented 5 years ago

I suggest dropping your ~/.config/composer and seeing if an old dependency in there is causing this.

Overall to be avoided: composer global

Einenlum commented 5 years ago

Thanks, it works when deleting my .config/composer dir.

For the record, previous global composer.json and composer.lock:

{
    "require": {
        "laravel/lumen-installer": "^1.1",
        "vimeo/psalm": "^3.4"
    }
}

composer.lock

bramus commented 4 years ago

Same thing happens when running a composer install with a composer.json that has no dependencies (cross-linking the https://github.com/composer/composer/issues/8336 issue)

This scenario should be caught I guess, as it breaks basic workings of Composer: With an "empty" composer.json, Composer should create a vendor folder and a composer.lock file. With ocramius/package-versions globally installed (as a dependency of – for example – symfony/console) this behavior breaks.