Error while installing composer on symfony 4 - php

This was the result that I get when I ran composer install to update composer dependencies and I've removed composer.lock to make sure updated dependencies will be downloaded.
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
!!
!! Fatal error: Declaration of App\Middleware\EventBusMiddleware::handle($message, callable $next) must be compatible with Symfony\Component\Messenger\Middleware\MiddlewareInterface::handle(Symfony\Component\Messenger\Envelope $envelope, Symfony\Component\Messenger\Middleware\StackInterface $stack): Symfony\Component\Messenger\Envelope in /var/www/html/src/Middleware/EventBusMiddleware.php on line 8
!!
!! In EventBusMiddleware.php line 8:
!!
!! Compile Error: Declaration of App\Middleware\EventBusMiddleware::han
!! dle($message, callable $next) must be compatible with Symfony\Component\Mes
!! senger\Middleware\MiddlewareInterface::handle(Symfony\Component\Messenger\E
!! nvelope $envelope, Symfony\Component\Messenger\Middleware\StackInterface $s
!! tack): Symfony\Component\Messenger\Envelope
!!
!!
!!
Script #auto-scripts was called via post-install-cmd
Can someone help me with understanding this error?

Related

"Class not found" error when deploying Symphony to Heroku

When I try to deploy my code to heroku (git), my deployment fails with the following error message:
Generating optimized autoload files
83 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Run composer recipes at any time to see the status of your Symfony recipes.
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
!! Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#70
!! #message: """
!! Attempted to load class "DebugBundle" from namespace "Symfony\Bundle\DebugBundle".\n
!! Did you forget a "use" statement for another namespace?
!! """
!! #code: 0
!! #file: "./vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php"
!! #line: 132
!! trace: {
!! ./vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:132 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:386 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:786 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:128 { …}
!! ./vendor/symfony/framework-bundle/Console/Application.php:168 { …}
!! ./vendor/symfony/framework-bundle/Console/Application.php:74 { …}
!! ./vendor/symfony/console/Application.php:171 { …}
!! ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54 { …}
!! ./vendor/autoload_runtime.php:35 { …}
!! ./bin/console:11 {
!! ›
!! › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
!! ›
!! arguments: {
!! "/tmp/build_bdf9f8d3/vendor/autoload_runtime.php"
!! }
!! }
!! }
!! }
!! 2022-08-27T11:43:06+00:00 [critical] Uncaught Error: Class "Symfony\Bundle\DebugBundle\DebugBundle" not found
!!
Script #auto-scripts was called via post-install-cmd
! ERROR: Dependency installation failed!
!
! The 'composer install' process failed with an error. The cause
! may be the download or installation of packages, or a pre- or
! post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
! in your 'composer.json'.
!
! Typical error cases are out-of-date or missing parts of code,
! timeouts when making external connections, or memory limits.
!
! Check the above error output closely to determine the cause of
! the problem, ensure the code you're pushing is functioning
! properly, and that all local changes are committed correctly.
!
! For more information on builds for PHP on Heroku, refer to
! https://devcenter.heroku.com/articles/php-support
! Push rejected, failed to compile PHP app.
! Push failed

Symfony error when trying to create a new project: Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read .env

Whenever I try to create a new Symfony project using the following command:
composer create-project symfony/skeleton new_project
I'm getting these error messages in the console and I have no idea what causes it:
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
!!
!! Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read the "C:\Users\ferra\Projects\PHPex\test_project/.env" environment file. in C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php:567
!! Stack trace:
!! #0 C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php(114): Symfony\Component\Dotenv\Dotenv->doLoad(false, Array)
!! #1 C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php(157): Symfony\Component\Dotenv\Dotenv->loadEnv('C:\\Users\\ferra\\...', 'APP_ENV', 'dev', Array, false)
!! #2 C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\runtime\SymfonyRuntime.php(107): Symfony\Component\Dotenv\Dotenv->bootEnv('C:\\Users\\ferra\\...', 'dev', Array, false)
!! #3 C:\Users\ferra\Projects\PHPex\test_project\vendor\autoload_runtime.php(23): Symfony\Component\Runtime\SymfonyRuntime->__construct(Array)
!! #4 C:\Users\ferra\Projects\PHPex\test_project\bin\console(11): require_once('C:\\Users\\ferra\\...')
!! #5 {main}
!! thrown in C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php on line 567
!! PHP Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read the "C:\Users\ferra\Projects\PHPex\test_project/.env" environment file. in C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php:567
!! Stack trace:
!! #0 C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php(114): Symfony\Component\Dotenv\Dotenv->doLoad(false, Array)
!! #1 C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php(157): Symfony\Component\Dotenv\Dotenv->loadEnv('C:\\Users\\ferra\\...', 'APP_ENV', 'dev', Array, false)
!! #2 C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\runtime\SymfonyRuntime.php(107): Symfony\Component\Dotenv\Dotenv->bootEnv('C:\\Users\\ferra\\...', 'dev', Array, false)
!! #3 C:\Users\ferra\Projects\PHPex\test_project\vendor\autoload_runtime.php(23): Symfony\Component\Runtime\SymfonyRuntime->__construct(Array)
!! #4 C:\Users\ferra\Projects\PHPex\test_project\bin\console(11): require_once('C:\\Users\\ferra\\...')
!! #5 {main}
!! thrown in C:\Users\ferra\Projects\PHPex\test_project\vendor\symfony\dotenv\Dotenv.php on line 567
!!
Script #auto-scripts was called via post-update-cmd
The following command: 'symfony check:requirements' shows that my system is ready to run Symfony projects:
> PHP is using the following php.ini file:
C:\xampp\php\php.ini
> Checking Symfony requirements:
..............WWW......W..
[OK]
Your system is ready to run Symfony projects
Optional recommendations to improve your setup
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm not getting any errors when I try to create a demo project instead of a regular one (symfony new --demo new_project).
Does anyone know what's causing the error message when trying to create a new regular Symfony project?
Any kind of help is appreciated.
The only solution at the moment is to create the file .env manualy at the root of your project.
I encountered the error in composer version 1. Fortunately, I was able to fix this issue by updating to the latest version of the composer.
sudo composer self-update --2

Symfony 5.3 The parameter "21" must be defined

i developed a symfony project.
Everything words fine on dev machines (using symfony server on port 8000).
When i clone the git in my production server i got this error:
Executing script cache:clear [KO] [KO] Script cache:clear returned
with error code 1 !! !! // Clearing the cache for the prod
environment with debug !! // false !! !! !! In
App_KernelProdContainer.php line 674: !! !! The parameter "21" must
be defined. !! !! !! cache:clear [--no-warmup]
[--no-optional-warmers] !! !! Script #auto-scripts was called via
post-update-cmd
I tried to:
delete the var/cache/* content
execute a php bin/console cache:pool:clear cache.global_clearer
set the env to prod and to dev
Nothing changes.
I have an ubuntu 20 with php-fpm7.4, mysql 8.0.
The error log shows:
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException:
The parameter "21" must be defined. in
/var/www/html/lavanderiasolari/public_html/laundry_manager/var/cache/prod/ContainerJ6TfZkC/App_KernelProdContainer.php:674\nStack
trace:\n#0
/var/www/html/lavanderiasolari/public_html/laundry_manager/vendor/symfony/dependency-injection/EnvVarProcessor.php(281): ContainerJ6TfZkC\App_KernelProdContainer->getParameter()\n#1
[internal function]:
Symfony\Component\DependencyInjection\EnvVarProcessor->Symfony\Component\DependencyInjection\{closure}()\n#2
/var/www/html/lavanderiasolari/public_html/laundry_manager/vendor/symfony/dependency-injection/EnvVarProcessor.php(277): preg_replace_callback()\n#3
/var/www/html/lavanderiasolari/public_html/laundry_manager/vendor/symfony/dependency-injection/Container.php(415):
Symfony\Component\DependencyInjection\EnvVarProcessor->getEnv()\n#4
/var/www/html/lavanderiasolari/public_html/laundry_manager/var/cache/prod/Contai...'
I executed composer dump-env .env and he generated .env.local.php, with
return array (
'APP_ENV' => 'prod',
'APP_SECRET' => 'c6e083dd648f30951fb991cee1df42f9',
'DATABASE_URL' => 'mysql://[DBUSER]:'.urlencode('[dbpasswd]').'#127.0.0.1:3306/[dbname]?serverVersion=8.0',
);
What shall i do?
Thanks a lot.
Having the same error. The problem is comming from special characters in your password.
Indeed in .env variables you need to url encode. For example != become %21%2F but it cause error
The parameter “21” must be defined
Solution in config/packages/doctrine.yaml replace
url: '%env(resolve:DATABASE_URL)%'
by
url: '%env(DATABASE_URL)%'

Downgrading Twig: Uncaught Error: Call to undefined method Twig\Environment

I'm using Symfony 4.4 on a project and I need to use stfalcontinymce. Since I'm on SF4 I need the version 2.4. So I did this:
composer require stfalcon/tinymce-bundle=2.4
But then I get this error:
!! 11:03:44 CRITICAL [php] Uncaught Error: Class 'Twig_Extension' not found ["exception" => Error { …}]
!!
!! In StfalconTinymceExtension.php line 13:
!!
!! Attempted to load class "Twig_Extension" from the global namespace.
!! Did you forget a "use" statement?
Someone told me that it's because this version doesn't get along with Twig 3 so I need to downgrade my Twig version. I then did this to downgrade Twig:
composer require twig/twig=2
But then I get this error:
13:14:07 CRITICAL [php] Uncaught Error: Call to undefined method Twig\Environment::registerUndefinedTokenPa
rserCallback() ["exception" => Error { …}]
!!
!! In srcApp_KernelDevDebugContainer.php line 2040:
!!
!! Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environm ent".
!! Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?
I tried adding in composer.json
"twig/extensions": "*"
Then composer install, then running the command:
composer require stfalcon/tinymce-bundle=2.4 -W
And I get this error:
!! 13:49:04 CRITICAL [php] Uncaught Error: Call to undefined method
Twig\Environment::registerUndefinedTokenParserCallback() ["exception" => Error { …}]
!!
!! In srcApp_KernelDevDebugContainer.php line 2045:
!!
!! Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environment".
!! Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?
I'm really lost here. Can someone help? thanks
Your executed commands don't seem to be possible on my system at all since there will be version constraint conflicts.
Instead of restricting to one version for your dependencies, you should use a constraint.
Your require in composer.json may contain something like the following
"twig/twig": "^2",
"stfalcon/tinymce-bundle": "2.4.*",
"twig/extra-bundle": "^2"
The constraints are explained here. But the ^2 basically means >= 2.x.x and < 3.0.0
For the tinymce bundle I used the above because of the this GitHub issue
Furthermore twig/extensions seems to be deprecated, and this GitHub issue mentions twig/extra-bundle which is needed and may be its replacement.

Clear cache command gets an error error after installing api-platform.com [duplicate]

This question already has an answer here:
"Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance..."
(1 answer)
Closed 2 years ago.
I'm trying to install api-platform but I'm having problems after launching my composer install:
I follow the official docs for installation with:
composer req api
When I start the server or when I try to run composer install I get this error:
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
and then a warning:
[WARNING] Some commands could not be registered:
!!
!!
!! In DoctrineOrmPropertyMetadataFactory.php line 31:
!!
!! Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property
!! \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D
!! octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc
!! trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co
!! ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040
!!
!!
!! In DoctrineOrmPropertyMetadataFactory.php line 31:
!!
!! Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property
!! \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D
!! octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc
!! trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co
!! ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040
!!
!!
!! [WARNING] Some commands could not be registered:
!!
!!
!! In DoctrineOrmPropertyMetadataFactory.php line 31:
!!
!! Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property
!! \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D
!! octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc
!! trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co
!! ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040
!!
!!
!! In DoctrineOrmPropertyMetadataFactory.php line 31:
!!
!! Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property
!! \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D
!! octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc
!! trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co
!! ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040
!!
!!
!! // Clearing the cache for the dev environment with debug
!! // true
!!
!!
!! In DoctrineOrmPropertyMetadataFactory.php line 31:
!!
!! Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property
!! \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D
!! octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc
!! trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co
!! ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040
!!
!!
!! cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
!!
!! 2020-08-25T12:06:30+02:00 [critical] Uncaught Error: Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/ContainerPA69O1T/App_KernelDevDebugContainer.php on line 1040
Why am I getting this error, and what can I do to circumvent it?
NEWS : It Seems that adding these lines in your composer.json at the conflict property works !
"conflict": {
"symfony/symfony": "*",
"doctrine/common": ">=3.0",
"doctrine/persistence": "<1.3"
},
So i got this problem since this morning and i looked for a solution and didn't found it so i made my own DIY solution and it's working Pretty find for me Then i'm gonna share it :
Firstly you need to go in the following path and open the file in it with your code editor:
C:\YOUR_PROJECT\vendor\api-platform\core\src\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory.php
Once you opened it, you need to REPLACE the line 19 (use Doctrine\Common\Persistence\ManagerRegistry;) with the following one:
use Symfony\Bridge\Doctrine\ManagerRegistry;
AND THAT'S ALL FOLKS !
SCREENSHOT OF THE LINE
PS: If you're still having issues or not founding the Vendor\api-platform, you just need to open the composer.json and temporary delete the Following line :
"cache:clear": "symfony-cmd",
And run again the command:
composer req api
we have the same problem since yesterday!
I tried to change the version of the bundle, to an older version . But without any successful result.
Current dependency:
"api-platform/api-pack": "^1.2"
But the problem is solved on GitHub. To be tested...
https://github.com/symfony/symfony/issues/37936
UPDATE: We have to wait for a release of api-platform bundle.
https://github.com/api-platform/core/issues/3683
Temporarily, you can add this to composer.json :
"conflict": {
...
"doctrine/common": ">=3.0",
"doctrine/persistence": "<1.3"
}
It works for me.
https://github.com/api-platform/core/issues/3683#issuecomment-681039267
I have the same problem but when i add the following lines
"conflict": { ... "doctrine/common": ">=3.0", "doctrine/persistence": "<1.3" }
in my composer.json file the problem was resolved

Categories