psalm icon indicating copy to clipboard operation
psalm copied to clipboard

./vendor/bin/psalm --init PHP Fatal error: Uncaught Psalm\Exception\ConfigException: Config not found for path

Open k3vl4rAtWork opened this issue 1 year ago • 9 comments

Just getting started here with attempting to use PSALM on a small codebase and cant get the configuration generated. Any help is appreciated.

All I've done is the composer require, and then attempted to run the psalm init to create the configuration:

`$ ./vendor/bin/psalm --init PHP Fatal error: Uncaught Psalm\Exception\ConfigException: Config not found for path C:\Users\project\vendor\bin\psalm in C:\Users\project\vendor\vimeo\psalm\src\Psalm\Checker\ProjectChecker.php:767 Stack trace: #0 C:\Users\project\vendor\vimeo\psalm\src\Psalm\Checker\ProjectChecker.php(448): Psalm\Checker\ProjectChecker->getConfigForPath() #1 C:\Users\project\vendor\vimeo\psalm\bin\psalm(172): Psalm\Checker\ProjectChecker->checkFile() #2 C:\Users\project\vendor\bin\psalm(119): include('...') #3 {main} thrown in C:\Users\project\vendor\vimeo\psalm\src\Psalm\Checker\ProjectChecker.php on line 767

Fatal error: Uncaught Psalm\Exception\ConfigException: Config not found for path C:\Users\project\vendor\bin\psalm in C:\Users\project\vendor\vimeo\psalm\src\Psalm\Checker\ProjectChecker.php:767 Stack trace: #0 C:\Users\project\vendor\vimeo\psalm\src\Psalm\Checker\ProjectChecker.php(448): Psalm\Checker\ProjectChecker->getConfigForPath() #1 C:\Users\project\vendor\vimeo\psalm\bin\psalm(172): Psalm\Checker\ProjectChecker->checkFile() #2 C:\Users\project\vendor\bin\psalm(119): include('...') #3 {main} thrown in C:\Users\project\vendor\vimeo\psalm\src\Psalm\Checker\ProjectChecker.php on line 767 `

k3vl4rAtWork avatar Aug 12 '24 15:08 k3vl4rAtWork

Hey @k3vl4rAtWork, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

psalm-github-bot[bot] avatar Aug 12 '24 15:08 psalm-github-bot[bot]

Hey @k3vl4rAtWork, I was getting the same error, then realized that a very old Psalm have been installed when I ran composer require --dev vimeo/psalm. Psalm 0.13.14 was installed. The ProjectChecker.php file does not even exist in the newer version which got me confused for a second.

The old Psalm version was installed because I had installed nikic/php-parser 5.1 as well, and seems Psalm requires 4.19. You can see if your Psalm is outdated with composer outdated.

And if it is, you can see why by running composer why-not vimeo/psalm:^5.15 for example.

You can then install Psalm by upgrading/downgrading dependencies with

composer require --dev vimeo/psalm --with-all-dependencies

Or by installing the phar version.

Hope that helps, let me know.

spaze avatar Sep 07 '24 23:09 spaze

Yep, that should fix the issue. I wonder if it's possible to remove those old versions from packagist (ideally keeping the tags).

weirdan avatar Sep 08 '24 00:09 weirdan

You can @weirdan, in the Packagist web UI, click the ❌ icons next to the version you want to drop from Composer (see pic), the git/GitHub tag will stay. I have just tried that with one of my abandoned packages, there's no 0.1.0 which I have deleted in Packagist a minute ago, but the tag still exists.

image

spaze avatar Sep 08 '24 00:09 spaze

Then we need to remove all versions between 0.1.2 and 0.3.14 (both ends inclusive), as all of them had unbounded constraint (>= to be exact) on nikic/php-parser dependency.

Unfortunately, I can't do that myself as I'm not listed as Psalm's maintainer on Packagist, but I contacted Psalm's original author with a request to do this.

weirdan avatar Sep 08 '24 00:09 weirdan

Unfortunately, I can't do that myself

I can now. The versions with unbounded constraints have been retracted.

weirdan avatar Sep 08 '24 01:09 weirdan

Nice, thanks @weirdan! This saves me some head scratching the next time it would happen :-)

spaze avatar Sep 08 '24 01:09 spaze

@k3vl4rAtWork would you mind checking with the latest version?

weirdan avatar Sep 09 '24 18:09 weirdan

Hey @k3vl4rAtWork, I was getting the same error, then realized that a very old Psalm have been installed when I ran composer require --dev vimeo/psalm. Psalm 0.13.14 was installed. The ProjectChecker.php file does not even exist in the newer version which got me confused for a second.

The old Psalm version was installed because I had installed nikic/php-parser 5.1 as well, and seems Psalm requires 4.19. You can see if your Psalm is outdated with composer outdated.

And if it is, you can see why by running composer why-not vimeo/psalm:^5.15 for example.

You can then install Psalm by upgrading/downgrading dependencies with

composer require --dev vimeo/psalm --with-all-dependencies

Or by installing the phar version.

Hope that helps, let me know.

Yeah, your trick is very helpful @spaze . Thank alot!

In my case, by running composer why-not vimeo/psalm 5.26 showed that it needs nikic/php-parser (^4.17)

amculin avatar Sep 12 '24 02:09 amculin

Unfortunately, I find no way to install psalm alongside phpunit:

  Problem 1
    - Root composer.json requires vimeo/psalm ^5.26.1 -> satisfiable by vimeo/psalm[5.26.1].
    - phpunit/phpunit[11.4.2, ..., 11.5.1] require phpunit/php-code-coverage ^11.0.7 -> satisfiable by phpunit/php-code-coverage[11.0.7, 11.0.8].
    - phpunit/phpunit[11.3.2, ..., 11.4.1] require phpunit/php-code-coverage ^11.0.6 -> satisfiable by phpunit/php-code-coverage[11.0.6, 11.0.7, 11.0.8].
    - phpunit/phpunit[11.2.7, ..., 11.3.1] require phpunit/php-code-coverage ^11.0.5 -> satisfiable by phpunit/php-code-coverage[11.0.5, 11.0.6, 11.0.7, 11.0.8].
    - phpunit/phpunit[11.0.1, ..., 11.2.6] require phpunit/php-code-coverage ^11.0 -> satisfiable by phpunit/php-code-coverage[11.0.0, ..., 11.0.8].
    - phpunit/php-code-coverage[11.0.7, ..., 11.0.8] require nikic/php-parser ^5.3.1 -> satisfiable by nikic/php-parser[v5.3.1].
    - phpunit/php-code-coverage 11.0.6 requires nikic/php-parser ^5.1.0 -> satisfiable by nikic/php-parser[v5.1.0, v5.2.0, v5.3.0, v5.3.1].
    - phpunit/php-code-coverage[11.0.0, ..., 11.0.5] require nikic/php-parser ^5.0 -> satisfiable by nikic/php-parser[v5.0.0, ..., v5.3.1].
    - Conclusion: don't install nikic/php-parser v5.3.1 (conflict analysis result)
    - Root composer.json requires phpunit/phpunit ^11.0.1 -> satisfiable by phpunit/phpunit[11.0.1, ..., 11.5.1].

stefanhuber avatar Dec 16 '24 19:12 stefanhuber

Unfortunately, I find no way to install psalm alongside phpunit:

You may try installing the Psalm Phar distribution https://github.com/psalm/phar

More info here https://github.com/vimeo/psalm/blob/5.x/docs/running_psalm/installation.md#using-the-phar

spaze avatar Dec 16 '24 19:12 spaze