Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Fatal error after adding composer packages #8

Open
robrecord opened this issue Apr 10, 2019 · 10 comments
Open

Fatal error after adding composer packages #8

robrecord opened this issue Apr 10, 2019 · 10 comments

Comments

@robrecord
Copy link

I am getting the following errors after I add/remove requirements in composer, which seem to relate to a package that the SpinupWP cache plugin requires:

PHP Warning:  require_once(/Users/myuser/Sites/mywebsite/vendor/lkwdwrd/wp-muplugin-loader/src/lkwdwrd/Composer/../../../vendor/lkwdwrd/wp-muplugin-loader/src/lkwdwrd/mu-loader.php): failed to open stream: No such file or directory in /Users/myuser/Sites/mywebsite/web/app/mu-plugins/mu-require.php on line 2
PHP Stack trace:
PHP   1. {main}() /usr/local/Cellar/wp-cli/2.1.0/bin/wp:0
PHP   2. include() /usr/local/Cellar/wp-cli/2.1.0/bin/wp:4
PHP   3. include() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/php/boot-phar.php:11
PHP   4. WP_CLI\bootstrap() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:25
PHP   5. WP_CLI\Bootstrap\LaunchRunner->process() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:74
PHP   6. WP_CLI\Runner->start() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23
PHP   7. WP_CLI\Runner->load_wordpress() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1114
PHP   8. require() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1191
PHP   9. include_once() /Users/myuser/Sites/mywebsite/web/wp/wp-settings.php:278

PHP Fatal error:  require_once(): Failed opening required '/Users/myuser/Sites/mywebsite/vendor/lkwdwrd/wp-muplugin-loader/src/lkwdwrd/Composer/../../../vendor/lkwdwrd/wp-muplugin-loader/src/lkwdwrd/mu-loader.php' (include_path='.:/usr/local/Cellar/[email protected]/7.3.1/share/[email protected]/pear') in /Users/myuser/Sites/mywebsite/web/app/mu-plugins/mu-require.php on line 2
PHP Stack trace:
PHP   1. {main}() /usr/local/Cellar/wp-cli/2.1.0/bin/wp:0
PHP   2. include() /usr/local/Cellar/wp-cli/2.1.0/bin/wp:4
PHP   3. include() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/php/boot-phar.php:11
PHP   4. WP_CLI\bootstrap() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:25
PHP   5. WP_CLI\Bootstrap\LaunchRunner->process() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:74
PHP   6. WP_CLI\Runner->start() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23
PHP   7. WP_CLI\Runner->load_wordpress() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1114
PHP   8. require() phar:///usr/local/Cellar/wp-cli/2.1.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1191
PHP   9. include_once() /Users/myuser/Sites/mywebsite/web/wp/wp-settings.php:278

Looking at the file mu-plugins/mu-require.php:

<?php
require_once '/Users/myuser/Sites/mywebsite/vendor/lkwdwrd/wp-muplugin-loader/src/lkwdwrd/Composer' . '/../../../vendor/lkwdwrd/wp-muplugin-loader/src/lkwdwrd/mu-loader.php';

This is resolvable by doing composer update --lock which changes the contents of the file to this working code:

<?php
require_once __DIR__ . '/../../../vendor/lkwdwrd/wp-muplugin-loader/src/lkwdwrd/mu-loader.php';

Whenever I do anything that starts with composer require, the file mu-require.php changes back again and the fatal error returns.

I should mention that I am using bedrock by roots, and that bedrock installs a similar mu-plugin autoloader. Disabling this autoloader has no effect on any of the above process.

I'm not sure why this package lkwdwrd/wp-muplugin-loader is needed, since you seem not to have used it at all? The site seems to work fine without it, though I wouldn't know if your plugin then works correctly or not since it doesn't appear in the plugins list (maybe it should).

@polevaultweb
Copy link
Contributor

@robrecord can you try running composer dump-autoload

@polevaultweb
Copy link
Contributor

And add the o flag when you do composer require vendor/package -o

@robrecord
Copy link
Author

Thanks Iain.

After testing, doing composer dump-autoload beforehand doesn't have any effect on what's happening. It does have the same effect as composer update --lock, after the situation occurs (ie. fixes it temporarily).

Running composer require with -o has no effect on the situation - it still updates mu-require.php with the weird path that produces the error.

Is the package required for the plugin to work?

@polevaultweb
Copy link
Contributor

Sorry @robrecord, i've been running composer dump-autoload after installing/removing packages.

@polevaultweb
Copy link
Contributor

and when composer install is run on production, i use the -o flag.

@robrecord
Copy link
Author

robrecord commented Apr 10, 2019

I've seen the suggestion to run composer install --optimize-autoloader in the SpinupWP interface, wasn't aware of it before - nice tip. I'm now using that in production.

I've not ever had to use composer dump-autoload, also new to me.

Hoping there is a chance this plugin can work without having to use extra commands.

@polevaultweb
Copy link
Contributor

Yeah it's not ideal, and we will look to improve that in the future.

@robrecord
Copy link
Author

robrecord commented Apr 10, 2019

Thank you!

Maybe consider this as a modern alternative if the functionality is required:
https://github.com/roots/bedrock/blob/master/web/app/mu-plugins/bedrock-autoloader.php

Or you could not prescribe the requirement, allowing the user to add the requirement if needed (as it is not needed when using roots/bedrock).

@robrecord
Copy link
Author

Edit: only seems to be happening now when I do composer require deliciousbrains/spinupwp-mu-plugin, although it wasn't before.

This might be a bug with lkwdwrd/wp-muplugin-loader, surfaced by altering the directory sturcture as bedrock does.

robrecord added a commit to robrecord/spinupwp-mu-plugin that referenced this issue Apr 10, 2019
To improve compatibility with Roots Bedrock.

Doesn't appear to be required, and produces errors (see spinupwp#8) when using bedrock.
@robrecord
Copy link
Author

robrecord commented Apr 10, 2019

I worked around this by creating a patch.

For others to use, do the following:

composer config repositories.spinupwp-fork '{"type": "vcs", "url": "https://github.com/robrecord/spinupwp-mu-plugin"}'
composer require "deliciousbrains/spinupwp-mu-plugin:dev-patch-1"
# optional, to remove old requirements
composer clear-cache
composer update --lock

To revert/undo this change:

composer config --unset repositories.spinupwp-fork
composer require "deliciousbrains/spinupwp-mu-plugin:^1.0"
composer clear-cache
composer update --lock

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

No branches or pull requests

2 participants