Related
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
I tried all the answers here, but no luck.
The weird part is that if I simply run the command composer update I get this:
forge#development:~/default$ composer update
Cannot create cache directory /home/forge/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/forge/.composer/cache/files/, or directory is not writable. Proceeding without cache
> php artisan clear-compiled
The compiled class file has been removed.
> php artisan ide-helper:generate
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Predis\Client' not found
Running just php artisan ide-helper:generate gives me
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Predis\Client' not found
Deleting the entire vendor directory then running composer install gives me this output.
This is my composer.lock and my composer.json files.
Running the command composer require predis/predis also returns the same error:
> php artisan clear-compiled
The compiled class file has been removed.
> php artisan ide-helper:generate
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Predis\Client' not found
Do you have any ideas?
Update
This is a work around, but not a root solution. Running:
composer update --no-scripts
that will skip the
"scripts": {
"post-install-cmd": [
..
],
"pre-update-cmd": [
"php artisan clear-compiled",
"php artisan ide-helper:generate",
"php artisan ide-helper:models -N",
"php artisan optimize"
],
part, which is good enough for now. This indeed seems like a bug with laravel-ide-helper, reporting bug soon.
From the laravel-ide-helper readme:
When you receive a FatalException about a class that is not found, check your config (for example .... remove Redis ServiceProvider when you don't use it)
So, remove RedisServiceProvider and Redis alias from config/app.php if you don't use Redis. Then clear config cache with php artisan config:clear.
I am developing a library for Laravel which contains a service provider. I have added this library to another project's composer.json file.
The composer.json file for the "main project" contains the following scripts.
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
]
},
I can include the library dependency just fine, except for one thing; the pre-update-cmd and post-update-cmd scripts throw an error and cause me a lot of headaches. When running sudo composer update to update the dependencies, I get the following error.
$ sudo composer update
> php artisan clear-compiled
PHP Fatal error: Class 'MyName\MyProject\MyAwesomeServiceProvider' not found in /Users/Me/dev/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'MyName\MyProject\MyAwesomeServiceProvider' not found
Script php artisan clear-compiled handling the pre-update-cmd event returned with an error
[RuntimeException]
Error Output: PHP Fatal error: Class 'MyName\MyProject\MyAwesomeServiceProvider'
not found in /Users/Me/dev/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
I have Googled around quite a bit before asking this question and read through pretty much everything related that I could find. Apparently this is a known issue that has been discussed in multiple GitHub issues within the Laravel repository. However, I have yet to find a workaround, even after having tried multiple ones.
It appears that the issue is that the Artisan commands bootstrap Laravel, which leads to an error because the service provider is not available at this point - or something like that. Moving the clear-compiled command to post-update-cmd causes the same error, which surprises me a bit because I thought the service provider would be available at this point.
The only thing that works for me is to manually comment out the line that includes the service provider in config/app.php before running composer update and then adding it again afterwards. I have been doing this for a few hours, and it is already bothering the heck out of me, and I really cannot believe that this issue is around.
Does anyone know how to work around this error so that I don't get the error that my service provider is not found when updating the Composer dependencies for my project?
EDIT:
Here is the composer.json file for the library.
{
"name": "my-name/my-project",
"type": "library",
"authors": [
{
"name": "My Name",
"email": "test#example.com"
}
],
"require": {
"php": ">=5.5.0",
"laravel/framework": "~5.2"
},
"autoload": {
"classmap": [],
"psr-4": {
"MyName\\MyProject\\": "src/"
}
}
}
Edit
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.
Original
After looking over the Github issue you posted in the comments, as well as the related issues, you may be in for a bit of a wait. Taylor would like to put a script in vendor/bin and change composer.json to run that, but it looks like they are waiting for a PR from the community, and won't actually implement this themselves.
You haven't done anything wrong; your autoloading is setup correctly. The issue is with Laravel right now.
Moving the command to the post-update-cmd script doesn't work because artisan will always try to load the cache files when they exist. When running the clear-compiled command, artisan loads the cache files (part of startup) before it ever tries to delete them.
Your best bet is to manually delete the cache files before artisan gets run. And, you need to do it outside of Laravel/Artisan. So, you can manually delete the files, or you can create a little script to do it and add that to your composer.json file (for your main project, not your package).
Files to delete:
Laravel 5.2:
bootstrap/cache/compiled.php
bootstrap/cache/services.php
Laravel 5.1:
bootstrap/cache/compiled.php
bootstrap/cache/services.json
Laravel 5.0:
vendor/compiled.php
storage/framework/compiled.php
vendor/services.json
storage/framework/services.json
When using composer install or composer update you can use --no-scripts option to skips execution of scripts defined in composer.json.
e. g.: composer update --no-scripts.
Source: https://getcomposer.org/doc/03-cli.md#install
composer update --no-scripts
this command will ignore command defined in composer.json,otherwise it will excute laravel command which will check if serviceProvider is loaded.
It looks like you're simply not including your ServiceProvider. Put this in your root project's composer.json:
{
"autoload": {
"psr-4": {
"App\\": "app/",
"MyName\\MyProject\\": "../relative/path/to/serviceprovider/"
}
}
}
Run This
composer install --ignore-platform-reqs
I have recently installed Laravel 5 via composer. I tried creating a new controller using artisan and I get the following error:
bootstrap/../vendor/autoload.php. Failed to open stream: No such file or directory. The "vendor" folder does not exist.
Am I missing something?
Run composer with --no-scripts
composer update --no-scripts
This shall fix the issue. I tried this on Mac and Linux.
Which OS you are using ?
For Windows :
Go to Command Prompt
set path to www/{ur project}
For me : www/laravel5
Then type this command : composer install
It will automatically install all dependency in vendor/
Run composer install in your root project folder (or php composer.phar install).
Turns out I didn't enable openssl in my php.ini so when I created my new project with composer it was installed from source. I changed that and ran
composer update
now the vendor folder was created.
Did you create a new project or did you clone an existing project?
If you cloned an existing project it's very important to run
composer install
That way all the dependencies that are missing will be installed.
But if you create a new project you should run this command to make a new project using composer
composer create-project laravel/laravel name-of-your-project
I encountered the same problem. It occurred because composer was not able to install the dependencies specified in composer.json file.
try running
composer install
If this does not solve the problem, make sure
the following php modules are installed
php-mbstring
php-dom
To install this extensions run the following in terminal
sudo apt-get install php-mbstring php-dom
once the installation is complete
try running the command in your project root folder
composer install
You need to regenerate autoload.php file. you can use dump-autoload to do that without having to go through an install or update.
use
composer dump-autoload
to generate autoload.php file again in /vendor directory.
Following this below step solved my problem. You may try
composer update --no-scripts
composer update
Just run this inside the directory where you installed your project
composer install
After checking php version and a lot of research , the problem was on Composer side so just run the following command
composer install --ignore-platform-reqs
This solution worked for me. The reason is not to have a vendor folder in your application.
Follow these steps:
if your project has composer.json file, delete it
then run
composer require phpspec/phpspec
That command add vendor folder to your project
go to your project folder via cmd. run the following command
composer update
it will install the missing vendor folder and files in your project.
but in some cases, it gives an error like "Your configuration does not allow connection to ....." in cmd.
for that go to your composer.json file,
change "secure-http": true to "secure-http": false
but in some cases (as was in my case) you may not find such line in your file. for that do the following action:
change "config": {
"preferred-install": "dist"
}
to
"config": {
"preferred-install": "dist",
"secure-http": false
}
and run again composer update command.
hope this will solve problem.
Just run the following commands,
composer update
Or
composer install
When the new project created the laravel require to load vendors to autoload the libraries ,
We use composer update to
composer update
Composer is a dependency manager allows you to delegate responsibility for managing your dependencies to a third party.
Just setup a new project using composer instead of laravel like this:
composer create-project --prefer-dist laravel/laravel myProje
Delete Vendor then composer install
I also had that error. But none of the above solved the issue. So i uninstalled and again installed the composer. Then i did composer update. and the problem was fixed.
You are missing vendor folder, probably its new cloned repository or new project
the vendor folder is populated by composer binary which reads composer.json file or system requirements and installs packaged under vendor folder and create an autoload script that has all classed
composer update
Before you carry out the following instructions you need to make sure you have composer installed globally on your machine;
Open you Mac terminal and run the following command:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
once composer is installed globally run the following command after you are in the directory of the project:
composer install
once completed in it update and install all the required packages.
I had same problem with laravel and artisan, the solution:
php artisan key:generate
We got an error because we have missing vendor folder in our project, The vendor directory contains our Composer dependencies.
Need /vendor folder because all packages are there and including all the classes Laravel uses, A problem can be solved after following just two steps:
composer update --no-scripts
composer update
--no-scripts: Skips execution of scripts defined in composer.json
composer update: This will check for newer versions of the libraries you required in your project. If a newer version is found and it's compatible with the version constraint defined in the composer.json file, it will replace the previous version installed. The composer.lock file will be updated to reflect these changes.
These two commands, we will Recreate the vendor folder in our project and after that our project will be working smoothly.
I added composer.lock file to .gitignore, after commit that file to repository error is gone :)
my problem is solved by
composer update
composer install
php artisan key:generate
if you any other problem you can clear cache and config
Clear Route cache:
php artisan route:cache
Clear View cache:
php artisan view:clear
Clear Config cache:
php artisan config:cache
Something I realise is your composer.json file will have some sort of script like
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
what works for me:
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
removing post install cmd helped running composer install without any issue.
Hope this helps
Cheers!!
I got this when I did composer update instead of composer install.
Delete vendor folder and run composer install command. It is working 100%
In my case I had to enable another extension, namely php_mbstring.dll in the php.ini file before it could work. It's listed under extension=php_mbstring.dll. Find it in the php.ini file and remove the semi-colon (;) in front of it and save the file.
After this run install composer again in the root directory of your Laravel applcication and is should work.
If you are a Windows user you may uninstall Composer. Then install Composer. After that you install Laravel. Maybe it will work.
this works for me:
after installing the project, I open the project's folder and run these two commands
composer update
composer require doctrine/dbal
I don't know if I am relevant -
I have downloaded the Github release of laravel and installed with lando, and failed to start it.
In lando recipe, I had to add php: 8.1 in .lando.yml
name: ltest1
recipe: laravel
config:
webroot: public
php: 8.1
and
$ lando ssh
$ composer install
$ php artisan key:generate
I am using windows 7 and trying to install laravel 4.2 using composer. My development environment is EasyPHP, but based on the research I have done, that is not the problem.
Every time I try to create a new laravel project, called "testapp", by running this command in my projects directory:
composer create-project laravel/laravel testapp --prefer-dist
.., the installation is successful up until the point where composer tries to generate the "autoload" files, outputting these lines:
Generating autoload files
Could not open input file: artisan
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
If I then navigate to the new folder called testapp created in my projects directory, and run
composer update
or
composer install
I get the same error at the end.
Although composer doesn't seem to be able to run any php artisan command, by navigating to my testapp folder and running:
php artisan {any command here}
I can accomplish any artisan command I want.
After doing some research, I found that the problem is with composer itself. Composer does not know how to find the artisan file.
One suggestion was that I edit the composer.json file so that artisan would be defined by an absolute path rather than a relative path. So I changed this:
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
to this:
"scripts": {
"post-install-cmd": [
"php C:\\Program Files (x86)\\EasyPHP-DevServer-14.1VC11\\data\\localweb\\projects\\testapp\\artisan clear-compiled",
"php C:\\Program Files (x86)\\EasyPHP-DevServer-14.1VC11\\data\\localweb\\projects\\testapp\\artisan optimize"
],
"post-update-cmd": [
"php C:\\Program Files (x86)\\EasyPHP-DevServer-14.1VC11\\data\\localweb\\projects\\testapp\\artisan clear-compiled",
"php C:\\Program Files (x86)\\EasyPHP-DevServer-14.1VC11\\data\\localweb\\projects\\testapp\\artisan optimize"
],
"post-create-project-cmd": [
"php C:\\Program Files (x86)\\EasyPHP-DevServer-14.1VC11\\data\\localweb\\projects\\testapp\\artisan key:generate"
]
},
within the composer.json file in my testapp folder. Now, when running
composer install
I got this output in the command prompt:
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json.
You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Generating autoload files
Script php C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\proje
cts\testapp\artisan clear-compiled handling the post-install-cmd event returned
with an error
[RuntimeException]
Error Output:
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-p
lugins] [--no-custom-installers] [--no-scripts] [--no-progress] [-v|vv|vvv|--ver
bose] [-o|--optimize-autoloader] [packages1] ... [packagesN]
Although I first thought that this output meant that changing the composer.json would not solve the problem, I was amazed to find that changing the composer.json worked when the absolute path contained no spaces.
For example. I went to C:\Users\AlexLeung\Desktop, ran
composer create-project laravel/laravel desktestapp --prefer-dist
got the initial error, then updated the composer.json in the new desktestapp folder to look like
"scripts": {
"post-install-cmd": [
"php C:\\Users\\AlexLeung\\Desktop\\desktestapp\\artisan clear-compiled",
"php C:\\Users\\AlexLeung\\Desktop\\desktestapp\\artisan optimize"
],
"post-update-cmd": [
"php C:\\Users\\AlexLeung\\Desktop\\desktestapp\\artisan clear-compiled",
"php C:\\Users\\AlexLeung\\Desktop\\desktestapp\\artisan optimize"
],
"post-create-project-cmd": [
"php C:\\Users\\AlexLeung\\Desktop\\desktestapp\\artisan key:generate"
]
},
, and running
composer install
was then successful. Although this shows I can install laravel if I just install it on a path with no spaces, I need to be able to install it in places under the "Program Files (x86)" directory since that is where EasyPHP, and its Apache web server root, are located. In trying to get the absolute path to work with spaces, I have tried using underscores, which ends up pointing to the wrong path, and \u0020, which generates the same error.
So the question remains:
How can I get composer to recognize the artisan file within the newly created testapp folder?
A set of resulting questions if the first can't be answered:
1. Is there a way to get composer to recognize the artisan file without me needing to change the composer.json to iunclude an absolute path for artisan?
2. Should I even be concerned about having the autoload files generated? (is it even necessary)
3. Would it be okay if I just moved my projects to the desktop (or any other path without spaces) anytime I needed to run composer update or install?
Overall I would like to have a complete installation of laravel and be able to use the convenient composer commands whenever I need to.
Maybe your issue has to do with some kind of permissions because you are trying to run commands inside "C:\Program Files (x86)". Try to deactivate UAC and see if that works.
Also try to run php artisan clear-compiled from the command line. It may not even be an issue with composer but with the PHP path. Verify that your Windows PATH variable knows where your php.exe is located.
I've just tested a clean install in a folder called "C:\MyPrograms\Some kind of folder\" and composer runs as expected, so it's may have nothing to do with spaces.
You can get composer to recognize php artisan, one way or another. My personal experience tells me that having developer tools installed in C:\Program Files is not a good idea because you will keep getting unexpected behaviors. I advice you to instal PHP, Apache, EasyPHP & whatever you need in a new folder (like "C:\MyPrograms").
Anyhow, even if you have PHP and Apache installed in the default program files folder, you can always set your Document Root of Apache to another location and this may also solve your issue.
As for your other questions:
2) Yes, it really is necessary. The autoload files (will be located in vendor/composer/) enable you to work with namespaces and to work with your own classes and never to include() or require() because it will be done by Laravel automatically.
3) I guess you could do that and it will work. But the hassle of moving your entire project every time you need a composer update seems to much trouble and wasted time.
I think you found a bug in Composer.
This line probably is supposed to make the commands used in the hooks executable:
https://github.com/composer/composer/blob/a8adbfeb9fc7861deade782938222714168a22a8/src/Composer/Command/RunScriptCommand.php#L89
I suspect that the result of realpath() with the binary directory will return the correct path, but including spaces. putenv() looks like operating directly on the shell, with it's parameter being "PATH=C:\Path with spaces\somewhere;C:\PreviousPaths\" - this might not be working on Windows.
You should add an issue on Github to get this fixed.
From experience, lots of software is not well prepared to deal with spaces in paths. I recently had to rename all my Jenkins job names because "job name === workspace directory name", and the backup module was acting up on the spaces.