Class 'Way\Generators\GeneratorsServiceProvider' not found - php

I’m attempting to get Laravel running on Google App Engine Standard. I already had it working on flexible, but requirements changed and we need standard now. I’m using the PHP 7.2 environment with Laravel 5.7. The deploy works but when trying to visit a page, I just get an error in the logs:
Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Way\Generators\GeneratorsServiceProvider' not found
at Illuminate\Foundation\Application->register (/srv/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:662)
Line 662 for me locally at least is just return new $provider($this); which doesn’t seem to be explicitly referencing the generators package.
That generator package appears to be way/generators but when I do composer require way/generators locally, it spits out a million different warnings followed by
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
In GeneratorsServiceProvider.php line 58:
Call to undefined method Illuminate\Foundation\Application::share()
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
From what I’ve read Laravel > 5 does not need the generators package as it already has it included but for some reason on GAE it’s trying to reference it (locally it runs fine with artisan serve). I’ve tried all sorts of composer post install commands, but nothing has helped.
"post-install-cmd": [
"php artisan cache:clear",
"php artisan optimize:clear",
"php artisan config:clear",
"php artisan config:cache",
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize",
"chmod -R 755 bootstrap\/cache"
]

As you mentioned in the comments, the issue stems from using xethron/migrations-generator (https://github.com/Xethron/migrations-generator) which requires additional manual setup of service providers in either config/app.php or app/Providers/AppServiceProvider.php. The strange thing is that its composer.json does not require way/generators, but rather includes another package which also contains the files (?) for way/generators. Very strange, but explains why things are getting messy upon a composer install.
As you've done, nuking it is an option or completing the manual setup may also okay, although way/generators is for older versions of Laravel and cannot necessarily be expected to work 100%.

If you are migrating to Laravel 6+ remove it and use the upgraded version of it.
composer remove --dev "xethron/migrations-generator"
If this doesn't work, then look for any ServiceProvider that integrates it into your code. Once you remove it, you can use:
composer require --dev laracasts/generators

Related

How to fix "Script #php artisan package:discover returned with error code 1" + "Class not found" without internet connection?

I am working on a legacy Laravel 6 app which is isolated from the rest of the system without internet connection, and when I try to run composer dump-autoload I get:
In ProviderRepository.php line 208: Class
'Facade\Ignition\IgnitionServiceProvider' not found
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
So I can't do what's described in this post:
Laravel with App Engine Standard Class 'Facade\Ignition\IgnitionServiceProvider' not found
Update #1: I added the missing class to the dont-discover array in composer.json, then it showed another class missing, so I started adding them one-by-one. Apparently the following 3 packages are "missing" (even though their files are there):
"facade/ignition", "laravel/ui", "nunomaduro/collision".
When added all these 3 to the dont-discover array, I was successfully able to run composer dump-autoload:
"extra": {
"laravel": {
"dont-discover": ["facade/ignition", "laravel/ui", "nunomaduro/collision"]
}
}
But still, I want to know if I can fix the issue with these 3 packages
Can I fix it without internet connection? Anything I can try to do manually?
Update #2:
I saw a comment on another post here suggesting moving the packages from require-dev to require. I did it, and it worked!
https://stackoverflow.com/a/59369455/18178584
In the same post, someone suggested it might be related to a bug when updating from composer 1.x to 2.x:
https://stackoverflow.com/a/67847239/18178584
But since I don't know exactly what happened here, which one of the above can be the cause? And, since the first solution solved it for me, is it safe to leave these 3 packages in require instead of require-dev?
Try to refresh your Laravel project, like:
composer run refresh
But for that to work, you first need to implement refresh script in composer.json file, like:
{
// ...
"scripts": {
"refresh": [
"#composer dump-autoload --no-scripts",
"#php artisan config:clear",
"#composer run post-autoload-dump --verbose",
"#php artisan cache:clear",
"#php artisan clear-compiled",
"#php artisan view:clear",
"#php artisan route:clear"
],
// ...
}
}
Also, as mentioned in comments, ensure important packages are in require section of composer.json (instead of require-dev).
Only unit-test and/or lint purpose packages should be in require-dev.
Details
Normally composer dump-autoload is enough, but sometimes post-autoload-dump uses cached class, hence php artisan config:clear needs to run first, but "config:clear" may crash if dump-autoload is not done yet.
Solution? Like above, use --no-scripts and trigger post-autoload-dump later manually ;-)
(Well not "manually", I do it all automatically, but you get the idea.)

Issues using php artisan on a laravel 5.7.* app

I've been trying to work on a laravel app but I can't even make it start.
I've run composer install, composer global update, composer udpate, composer self-update and several other commands,
I've deleted the vendor folder, the composer.lock file, re-ran composer install and things I've found online to no avail. This is the error I keep getting:
#php artisan package:discover
In Container.php line 779:
Class request does not exist
Script #php artisan package:discover handling the post-autoload-dump event returned with error code 1
Not sure where to go next. Any ideas?
I would suggest you remove your composer itself and re-install the composer. the try install you laravel packages with it.
Try clearing application cache using this command: php artisan cache:clear
The cache:clear command can be used to clear the applications cache files.
Don't worry about your laravel
check composer correctly installed on your system
check composer have access for READ and WRITE in your system
after your sure about things
check your laravel install in your system for PHP you have and find specific you php version composer connected to it (Those who have multi PHP)
then have two option:
composer global require laravel/installer
then laravel new blog or
composer create-project --prefer-dist laravel/laravel blog
then go to folder cd /projectName
Use PHP's built-in development server: php artisan serve

Class 'PragmaRX\Tracker\Vendor\Laravel\ServiceProvider' not found

I had installed PragmaRx\Tracker package several months ago into my project.
I started to deleting the package from laravel project through following steps:
1. composer remove vendor/PragmaRx/Tracker
2. remove package name form composer.json file
3. removing package from provider and aliases list in config/app.php file
4. composer dump-autoload
5. composer update
6. also php artisan dump-autoload
I also tried a bunch of other ways to remove the package.
after removing the package I'm getting this error when I run any artisan command (even "php artisan serve" command):
In ProviderRepository.php line 208:
Class 'PragmaRX\Tracker\Vendor\Laravel\ServiceProvider' not found
It's obvious that the package and its related files have been removed! but I couldn't find out the error's reason.
my laravel version is 5.5.4 .
any idea?
finally I found the error's reason.It's because of laravel cache!!
in one hand I couldn't run any artisan command including "php artisan config:cache" to clear laravel cache, in the other hand the cache was the error's reason.So at first I re-installed the pachage :
composer require PragmaRx/Tracker
then :
php artisan config:cache
and finally :
composer remove PragmaRx/Tracker
Done.

Laravel 5.5 - Issues creating new project

I'm trying to use Laravel 5.5. I updated my php 7.0 to php 7.1. Even, I update my laravel installer package. But, when I try to do:
laravel new myProject
I get this error:
You made a reference to a non-existent script #php -r
"file_exists('.env') || copy('.env.example', '.env');" You made a
reference to a non-existent script #php artisan key:generate
Illuminate\Foundation\ComposerScripts::postAutoloadDump You made a
reference to a non-existent script #php artisan package:discover
I am using laravel valet and if I go to the browser, when I try myProject.dev is not working. I see this error:
Whoops, looks like something went wrong.
I tried using:
php artisan key:generate
inside my project, but I got that:
[ErrorException]
file_get_contents(/Users/jorgeJimenez/Sites/laravel5-5/.env): failed
to ope n stream
: No such file or directory
I noticed, my laravel 5.4 projects are working. I copied a .env file and I put on my laravel 5.5 projects. After that, I run
php artisan key:generate
and the key was generated and my project in the browser works.
It's supposed, all that process is automatic, but I am not quite sure what is happening.
You can try update your composer:
composer self-update
I had the same problem. Then I found that there was no problem when i created the first project use laravel 5.5. so I clear composer's cache dir. It works well now.
This is because of your Laravel Installer or Composer version. I have faced the same problem and found following 2 different solutions:
Generally you can solve with by running composer global update command and then run composer update command from your project directory. This solution basically updates your installer and then your project.
If still, you have this issue, you need to run composer self-update command first and then run composer update command from your project directory. Here your composer will update and then your project.
Hope this answer will help you.

Fatal error: Class 'LaravelLocalization' not found after composer install in production

It's been 3 days since I'm working on translating my site, so I installed LaravelLocalization:
I did everything working in local, then I pushed it in production and executed:
composer install --no-interaction --no-dev
php artisan clear-compiled
php artisan optimize
composer dump-autoload -o
php artisan route:cache
php artisan config:cache
Now, all the "php artisan commands fail with:"
[Symfony\Component\Debug\Exception\FatalThrowableError]
Fatal error: Class 'LaravelLocalization' not found
In this case, in the composer install script, it fails in:
php artisan clear-compiled
I tried to run:
php artisan cache:clear
php artisan route:clear
But without any results...
Any ideas??? This is not the first time I get this kind of stuff, but I may say that this it's a pain in the ass :(
EDIT:
In my routes.php,
I deleted this line:
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect']],
around all my routes, and now composer install works.
But it doesn't solve my issue, because as soon as I put it back, I still get the same error :(
I resolved it removing the line:
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect']],
in my file routes.php
run again
composer install
and finally
php artisan config:clear
php artisan route:clear
What I don't know is why it happened, and if there is a way to prevent it...
as what the error says, it means that the composer can't locate your package. so be sure to
check your config/app.php file
be sure to put the package in providers and aliases arrays, respectively.
This has been a known issue for a while, but has actually finally been resolved recently. You can read about the issue here.
Basically, running php artisan loads the entire framework, including the cached files. Since the cached files don't have your service provider, you get the error. This includes running php artisan clear-compiled. So, it is using the cached files in the command that is used to delete the cached files.
This issue has finally been resolved as of laravel/framework:v5.2.25 and laravel/laravel:v5.2.27, and backported to laravel/framework:v5.1.33 and laravel/laravel:v5.1.33.
This fix includes a change to the Laravel application (laravel/laravel), in addition to the Laravel Framework (laravel/framework). To implement, you will need to:
1) Update the scripts section of your composer.json file to match that in the laravel/laravel package. Specifically:
remove the pre-update-cmd section
in the post-install-cmd section, replace "php artisan clear-compiled" with "Illuminate\\Foundation\\ComposerScripts::postInstall"
in the post-update-cmd section, replace "php artisan clear-compiled" with "Illuminate\\Foundation\\ComposerScripts::postUpdate"
2) Once you have updated your composer.json, run a composer update. If you only want to update the framework, you can run composer update laravel/framework.

Categories