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

Composer commands error after removing specific autoload file from composer.json #8601

Closed
VSlokker opened this issue Feb 13, 2020 · 5 comments
Closed
Labels

Comments

@VSlokker
Copy link

@VSlokker VSlokker commented Feb 13, 2020

We have a legacy project which autoloads specific files.
We are in the process of slowly removing the legacy code. When we remove those specific autoload files from the composer.json, composer will exit every command with an error.

It seems that when running composer dumpautoload, composer tries to load the existing generated autoload files before re-generating them, resulting in an error because one or more of the required files no longer exists.

We could probably work around this in team situations by first removing the line from composer.json and wait a while until everyone has updated their dependencies (and thus their autoload files), and then remove the actual file from the repository.
But this does not work for projects that have version and/or feature branches, where one might switch between the 2 states of composer.json.

Removing the existing generated autoload files fixes the problem.


My composer.json:

"autoload": {
        "psr-4": {
            "somenamespace\\": "src/somedir"
        },
        "files": [
            "app/somefile.php",
           // .... omitted for brevity
        ]
    },

Output of composer diagnose:

Exit Code: 255(Unknown error)

  Error Output:                                                                                                                                   
  ================ 
PHP Warning:  require(vendor/composer/../../app/somefile.php): failed to open stream:  
   No such file or directory in vendor/composer/autoload_real.php on line ..

When I run this command:

composer install
composer dumpautoload

I get the following output:

Exit Code: 255(Unknown error)

  Error Output:                                                                                                                                   
  ================ 
PHP Warning:  require(vendor/composer/../../app/somefile.php): failed to open stream:  
   No such file or directory in vendor/composer/autoload_real.php on line ..

And I expected this to happen:

Install dependencies and/or generate new autoload files.

@alcohol

This comment has been minimized.

Copy link
Member

@alcohol alcohol commented Feb 13, 2020

I am a bit confused about what the actual problem is here that you are describing?

As far as I can tell from your description, everything works exactly as expected, but it is simply inconvenient for you?

@alcohol alcohol added the Support label Feb 13, 2020
@VSlokker

This comment has been minimized.

Copy link
Author

@VSlokker VSlokker commented Feb 13, 2020

As i'm just a user of Composer, i am not aware of the internals of it. However, i am running into an error when running composer dumpautoload or composer install after making a change to my composer.json file, based on configuration i had before making the change. That strikes me as odd so that is why i created an issue.

Could you explain to me how this is expected behaviour? (Why does Composer need to load my existing autoload files to create autoload files for my new configuration?)

@alcohol

This comment has been minimized.

Copy link
Member

@alcohol alcohol commented Feb 13, 2020

Can you start by running the command in verbose mode so we have more useful information?
( a stacktrace of the error would be useful for example )

composer install|update -vvv

And also check if running it without plugins and scripts still causes the issue to occur:

composer install|update --no-scripts --no-plugins
@Seldaek

This comment has been minimized.

Copy link
Member

@Seldaek Seldaek commented Feb 13, 2020

I'd also suspect this is caused by a plugin which triggers autoloading of stuff during bootstrapping, because normally you are right dumping the autoloader should not require loading the previous one, as that previous one is most likely outdated.

If you can simply try your repro case again but with composer dumpautoload --no-plugins and check if that fixes it that'd be great.

That said, if that's the cause, we probably should make sure that files autoloads can be skipped if files are missing when we generate an in-memory autoloader. Let's see..

Edit: Never mind that last sentence, we don't load files autoload at all in in-memory autoloaders, so that can't be the problem.

@VSlokker

This comment has been minimized.

Copy link
Author

@VSlokker VSlokker commented Feb 14, 2020

It was indeed a plugin. We are using a coding-standards package which is depending on dealerdirect/phpcodesniffer-composer-installer.

Sorry for the inconvenience and thank you both for your replies. I learned something new about composer today.

@VSlokker VSlokker closed this Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.