"Class 'Symfony\Component\Translation\Loader\ArrayLoader' not found" - laravel

I tried creating new laravel project using composer but am getting the above error. Any help?
This is the command I used:
"composer create-project --prefer-dist laravel/laravel project-name"
Some Output errors:
Class Symfony\Component\Translation\Tests\DependencyInjection\TranslatorPassTest located in ./vendor/symfony/translation/TranslatorPassTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Symfony\Component\Translation\Loader\ArrayLoader located in ./vendor/symfony/translation/ArrayLoader.php does not comply with psr-4 autoloading standard. Skipping.
Class Symfony\Component\Translation\Tests\Provider\NullProviderFactoryTest located in ./vendor/symfony/translation/Provider/NullProviderFactoryTest.php does not comply with psr-4 autoloading standard. Skipping.

Until the namespace change is accounted for you can temporarily set
"symfony/translation": "v5.3.7"
Update it with composer update and it should work again.

The package has been updated to:
"symfony/translation": "v5.3.9"
and it is working well.
https://github.com/symfony/translation/releases/tag/v5.3.9

I have reverted my composer.lock and then just composer install. It seams that the translator new update is not properly set. For new installations the solution should be what the user3672987 gave as temp solution.

Temporary solution :
You can quick fix it by adding temporarily this line to your composer.json
"symfony/translation": "v5.3.7",
Initial answer :
Same for me, got this error when I'm trying to install a new project or using composer install or composer update on any project :
> #php artisan package:discover --ansi
Error
Class "Symfony\Component\Translation\Loader\ArrayLoader" not found
at vendor/nesbot/carbon/src/Carbon/Translator.php:80
76▕ public function __construct($locale, Translation\Formatter\MessageFormatterInterface $formatter = null, $cacheDir = null, $debug = false)
77▕ {
78▕ $this->initializing = true;
79▕ $this->directories = [__DIR__.'/Lang'];
➜ 80▕ $this->addLoader('array', new Translation\Loader\ArrayLoader());
81▕ parent::__construct($locale, $formatter, $cacheDir, $debug);
82▕ $this->initializing = false;
83▕ }
84▕
+13 vendor frames
14 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Carbon\Laravel\ServiceProvider))
+5 vendor frames
20 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Edit :
Apparently, the package symfony/translation had a minor release that changed the namespace of ArrayLoader :
https://github.com/symfony/translation/releases/tag/v5.3.8
https://github.com/briannesbitt/Carbon/issues/2466

Related

Cannot locate class of installed package

I'm writing a laravel package which contains spatie/laravel-sitemap.
I already included several external packages and I didn't encountered any issues, but for some reason I'm not able to integrate this one.
What I did is the usual:
composer require spatie/laravel-sitemap
Then I have created a Console command that have as handle method the following content:
public function handle()
{
SitemapGenerator::create(config('app.url'))
->configureCrawler(function (Crawler $crawler) {
$crawler->ignoreRobots();
})
->writeToFile(public_path('sitemap.xml'));
$this->line('<info>Sitemap generated');
}
when I execute the command registered as:
php artisan myapp:sitemap
I get:
Class "Spatie\Sitemap\SitemapGenerator" not found
The reference imported are:
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;
I also tried composer update and composer dump-autoload, same problem.
Any help?
register package class in providers array in config/app.php
Spatie\Sitemap\SitemapServiceProvider;
in the bottom of app.php file
i hope it was useful.
you can publish package using this.
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=sitemap-config
then
composer dump-autoload
for more details please check the document https://github.com/spatie/laravel-sitemap under Configuration

Call to undefined function Symfony\Component\Console\Input\escapeshellarg()

When running composer install in production I get a new error message today:
$ composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
Error
Call to undefined function Symfony\Component\Console\Input\escapeshellarg()
at vendor/symfony/console/Input/Input.php:195
191▕ * #return string
192▕ */
193▕ public function escapeToken(string $token)
194▕ {
➜ 195▕ return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
196▕ }
197▕
198▕ /**
199▕ * {#inheritdoc}
+1 vendor frames
2 [internal]:0
Symfony\Component\Console\Input\ArgvInput::Symfony\Component\Console\Input\{closure}("package:discover")
+8 vendor frames
11 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
I can't figure out what is wrong. I'm wondering if the dependencies have got into a funny state and I need to do a fresh install of the vendor directory?
Turns out the function escapeshellarg() was disabled by the hosting provider. Thank you Nico for your help!

my error : Class 'Maatwebsite\Excel\Excel' not found

this errormy composer.json:
...
"maatwebsite/excel": "^3.1",
...
I can run my project on localhost but when I upload on server I got this error message:
Class 'Maatwebsite\Excel\Excel' not found
my laravel version:
Laravel Framework 8.80.0
Please make sure that you imported class in config/app.php
If not then please add below line in prividers array in config/app.php file.
Maatwebsite\Excel\ExcelServiceProvider::class
then publish vendor by
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config
Then after
composer dump-autoload

no php artisan commands are working after new migration

I am new to laravel .
Following tutorial videos on laracast,i made a new migration (cmd command) like following
php artisan make:migration delete_title_from_posts_table
which gave me the message
Created Migration: 2020_02_05_185721_delete_title_from_posts_table
after that no php artisian command is working in cmd.
Any command i run gives me the following error
In Container.php line 805:
Target class [db] does not exist.
In Container.php line 803:
Class db does not exist
what would be causing this?
my laravel app version=6.2 and php version=7.3.5 on Win10 64-bit.
similar questions i already viewed,not working for me
artisan-commands-not-working-after-composer-update
in-container-php-line-805-target-class-db-does-not-exist
Since it's a facade, add this to the top of the class to make it work:
use DB;
Or use full namespace:
$tables = \DB::table...
run these commands steps by step:
composer dump-autoload clean up all compiled files and their paths
composer update --no-scripts Skips execution of scripts defined in composer.json
composer update update your project's dependencies

laravel PackageServiceProvider not found; moving from workbench to vendor

This is basically a problem of moving a laravel package from workbench to vendor, but the solutions in other threads have not worked in this case:
I have a package iateadonut/signup.
I created a fresh laravel installation (laravel_test), and, just for testing sake, I put iateadonut/signup in laravel_test/workbench/.
I put Iateadonut\Signup\SignupServiceProvider, in the 'providers' array in app.php.
I then run:
/laravel_test> php artisan dump-autoload
and get:
Generating optimized class loader
Running for workbench [iateadonut/signup]...
My package is successfully installed.
On a fresh installation of laravel (laravel_test), I then put iateadonut/signup in larael_test/vendor.
I put Iateadonut\Signup\SignupServiceProvider, in the 'providers' array in app.php.
I then run:
/laravel_test> php artisan dump-autoload
and get:
PHP Fatal error: Class 'Iateadonut\Signup\SignupServiceProvider' not found in /var/www/html/laravel_test/bootstrap/compiled.php on line 4214
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Iateadonut\Signup\SignupServiceProvider' not found","file":"/var/www/html/laravel_test/bootstrap/compiled.php","line":4214}}
Any idea what could be wrong?
Here is a more google friendly version in case someone else is looking for this:
PHP Fatal error: Class 'Vendor\Package\PackageServiceProvider' not found in /var/www/html/laravel/bootstrap/compiled.php on line 4214
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Vender\Package\PackageServiceProvider' not found","file":"/var/www/html/laravel/bootstrap/compiled.php","line":4214}}
Try to remove the the bootstrap/compiled.php file and try your composer dumpautoload again

Resources