Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run psalm without a composer autoloader #935

Closed
ewingd opened this issue Aug 8, 2018 · 13 comments
Closed

Cannot run psalm without a composer autoloader #935

ewingd opened this issue Aug 8, 2018 · 13 comments

Comments

@ewingd
Copy link

ewingd commented Aug 8, 2018

I have psalm installed globally and wanted to run it on a single file that has no includes and doesn't need or use an autoloader. I am attempting to create a minimum test case to reproduce an exception psalm is throwing on a larger project.

It refused to run with the message:

Could not find any composer autoloaders in <project_dir>
Add a --root=[your/project/directory] flag to specify a particular project to run Psalm on.

$ tree
.
├── psalm.xml
└── src
    └── main.php


$ cat psalm.xml 
<?xml version="1.0"?>
<psalm>
    <projectFiles>
        <directory name="src" />
    </projectFiles>
</psalm>
@weirdan
Copy link
Collaborator

weirdan commented Aug 8, 2018

Well, docs say psalm requires composer (and its autoloader). It doesn't need to be functional though, so you can work around this with composer init; composer install; psalm

@weirdan
Copy link
Collaborator

weirdan commented Aug 8, 2018

If you encounter 'No lockfile found' error you can safely ignore it.

@muglug
Copy link
Collaborator

muglug commented Aug 9, 2018

Well, docs say psalm requires composer (and its autoloader)

Yeah, although I can see why you might not want that. It shouldn't need composer (e.g. when running from the phar or from another directory) and I'll try and get that working properly.

@muglug muglug closed this as completed in a32273b Aug 9, 2018
@sebastianbergmann
Copy link
Contributor

I have this problem with Psalm 3.2.7:

$ ./tools/psalm --init
Failed to find a valid Composer ClassLoader in

Not even --version works:

$ ./tools/psalm --version
Failed to find a valid Composer ClassLoader in

However, --help works.

As soon as an autoloader generated using Composer exists in vendor/autoload.php it works:

$ composer init                                                   
  Welcome to the Composer config generator  

This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [sebastianbergmann/example]: 
Description []: 
Author [Sebastian Bergmann <sb@sebastian-bergmann.de>, n to skip]: 
Minimum Stability []: 
Package Type (e.g. library, project, metapackage, composer-plugin) []: 
License []: 

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? 
Search for a package: 
Would you like to define your dev dependencies (require-dev) interactively [yes]? 
Search for a package: 

{
    "name": "sebastianbergmann/example",
    "authors": [
        {
            "name": "Sebastian Bergmann",
            "email": "sb@sebastian-bergmann.de"
        }
    ],
    "require": {}
}

Do you confirm generation [yes]? 
$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
$ ./tools/psalm --version
Psalm 3.2.7.0@6e010d9db95275725e5ad6409c387eb173091f72

@muglug
Copy link
Collaborator

muglug commented Apr 18, 2019

@sebastianbergmann what's tools/psalm - is it a symlink to Psalm in another directory? I've added a slightly better error message in 5003533, but still need more info.

@sebastianbergmann
Copy link
Contributor

tools/psalm is https://github.com/vimeo/psalm/releases/download/3.2.7/psalm.phar (no symlink; installed using phive install --copy).

@muglug muglug reopened this Apr 20, 2019
@muglug muglug closed this as completed in 79ae72d Apr 20, 2019
@muglug
Copy link
Collaborator

muglug commented Apr 20, 2019

The original fix did not apply to the Phar, but I've just patched it to hopefully work more robustly.

@sebastianbergmann
Copy link
Contributor

I am seeing this problem (or a problem that looks like it) again with Psalm 5.1.0: without a Composer-generated autoloader present, Psalm refuses to start.

@weirdan
Copy link
Collaborator

weirdan commented Dec 4, 2022

@sebastianbergmann does this only happen for psalm.phar --init?

@sebastianbergmann
Copy link
Contributor

No, it is not limited to --init. A simple mkdir vendor && touch vendor/autoload.php works around this.

@weirdan
Copy link
Collaborator

weirdan commented Dec 4, 2022

@sebastianbergmann is there any way for me to reproduce it?

I tried, but everything seems to be working for me:

image

@sebastianbergmann
Copy link
Contributor

No, sorry, this is in an internal project. If/When I am able to reproduce it in a minimal and self-contained way then I will open a new ticket. Sorry for the noise!

@weirdan
Copy link
Collaborator

weirdan commented Dec 4, 2022

No problem. At the very least it led to error message improvement in #8827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants