Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Crashes.
03:04:51 ~$ composer global require drupal/coder
Changed current directory to /home/chriscalip/.composer
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Using version ^8.2 for drupal/coder
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing drupal/coder (8.2.10)
- Installing drupal/coder (8.2.12)
Downloading: 100%
Writing lock file
Generating autoload files
03:05:15 ~$ phpcs --standard=Drupal --report=diff /home/chriscalip/projects/sites-multi/d8-dev/modules/search_api_algolia/
PHP Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /home/chriscalip/.composer/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php on line 54
PHP Stack trace:
PHP 1. {main}() /home/chriscalip/phpcs.phar:0
PHP 2. PHP_CodeSniffer_CLI->runphpcs() /home/chriscalip/phpcs.phar:6
PHP 3. PHP_CodeSniffer_CLI->process() phar:///home/chriscalip/phpcs.phar/CodeSniffer/CLI.php:113
PHP 4. PHP_CodeSniffer->processFiles() phar:///home/chriscalip/phpcs.phar/CodeSniffer/CLI.php:998
PHP 5. PHP_CodeSniffer->processFile() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:653
PHP 6. PHP_CodeSniffer->_processFile() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:1772
PHP 7. PHP_CodeSniffer_File->start() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:1894
PHP 8. Drupal_Sniffs_InfoFiles_AutoAddedKeysSniff->process() phar:///home/chriscalip/phpcs.phar/CodeSniffer/File.php:576
03:05:24 ~$ composer global require symfony/yaml
Changed current directory to /home/chriscalip/.composer
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Using version ^3.2 for symfony/yaml
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing symfony/yaml (v3.1.5)
- Installing symfony/yaml (v3.2.8)
Downloading: 100%
Writing lock file
Generating autoload files
03:07:40 ~$ phpcs --standard=Drupal --report=diff /home/chriscalip/projects/sites-multi/d8-dev/modules/search_api_algolia/
PHP Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /home/chriscalip/.composer/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php on line 54
PHP Stack trace:
PHP 1. {main}() /home/chriscalip/phpcs.phar:0
PHP 2. PHP_CodeSniffer_CLI->runphpcs() /home/chriscalip/phpcs.phar:6
PHP 3. PHP_CodeSniffer_CLI->process() phar:///home/chriscalip/phpcs.phar/CodeSniffer/CLI.php:113
PHP 4. PHP_CodeSniffer->processFiles() phar:///home/chriscalip/phpcs.phar/CodeSniffer/CLI.php:998
PHP 5. PHP_CodeSniffer->processFile() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:653
PHP 6. PHP_CodeSniffer->_processFile() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:1772
PHP 7. PHP_CodeSniffer_File->start() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:1894
PHP 8. Drupal_Sniffs_InfoFiles_AutoAddedKeysSniff->process() phar:///home/chriscalip/phpcs.phar/CodeSniffer/File.php:576
03:07:43 ~$ phpcs --standard=Drupal /home/chriscalip/projects/sites-multi/d8-dev/modules/search_api_algolia/
PHP Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /home/chriscalip/.composer/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php on line 54
PHP Stack trace:
PHP 1. {main}() /home/chriscalip/phpcs.phar:0
PHP 2. PHP_CodeSniffer_CLI->runphpcs() /home/chriscalip/phpcs.phar:6
PHP 3. PHP_CodeSniffer_CLI->process() phar:///home/chriscalip/phpcs.phar/CodeSniffer/CLI.php:113
PHP 4. PHP_CodeSniffer->processFiles() phar:///home/chriscalip/phpcs.phar/CodeSniffer/CLI.php:998
PHP 5. PHP_CodeSniffer->processFile() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:653
PHP 6. PHP_CodeSniffer->_processFile() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:1772
PHP 7. PHP_CodeSniffer_File->start() phar:///home/chriscalip/phpcs.phar/CodeSniffer.php:1894
PHP 8. Drupal_Sniffs_InfoFiles_AutoAddedKeysSniff->process() phar:///home/chriscalip/phpcs.phar/CodeSniffer/File.php:576
03:08:19 ~$
Comments
Comment #2
chriscalip CreditAttribution: chriscalip commentedI installed phpcs the wrong way.
Comment #3
sanduhrsI'm experiencing the same issue, can you please explain your solution?
Comment #4
danielheramb CreditAttribution: danielheramb commented@chriscalip Can you describe how exactly you had phpcs installed the "wrong way"?
I'm getting this same error and am unsure if it has to do with my docker installation, the CodeSniffer config we've got in our project, the local version of CodeSniffer I've got installed through Homebrew, or something else altogether.
Comment #5
chriscalip CreditAttribution: chriscalip commented@sanduhrs
It's been awhile since I had this issue. Looking at my journal it seems doing a composer global install of yaml solved my problem.
Comment #6
chriscalip CreditAttribution: chriscalip commentedComment #7
arnoldbird CreditAttribution: arnoldbird commentedI'm not sure if this is more of a bug, or a support request, but when I try to install yaml globally, I get...
Comment #8
arnoldbird CreditAttribution: arnoldbird commentedI was able to resolve the problem. I'm not sure how. I added the following to the "require" section of my composer.json:
"symfony/yaml": "^3.1"
I also deleted core and vendor and ran composer update. I had to try it a few times.
It also may have helped me to run...
composer global require dealerdirect/phpcodesniffer-composer-installer
Comment #9
arnoldbird CreditAttribution: arnoldbird commentedI am running into the same issue again:
PHP Fatal error: Uncaught Error: Class 'Symfony\Component\Yaml\Yaml' not found in /root/.composer/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php:54
Comment #10
xpersonas CreditAttribution: xpersonas commentedI'm getting this too. DrupalPractice works. But Drupal does not.
Works:
phpcs --standard=DrupalPractice .
Fails:
phpcs --standard=Drupal .
Running
composer global require symfony/yaml
has not helped.Comment #11
pfrenssenPlease verify your installation. We have the Yaml library listed as a required dependency in
composer.json
so if it is missing you need to make sure it is installed correctly. Also check if any errors might have been output during the installation.Comment #12
xpersonas CreditAttribution: xpersonas commentedEverything seems ok. Let me add my composer contents. Maybe something is off I don't realize, but like I said "DrupalPractice" works fine. Maybe you'll recognize something off with how I'm trying to do this.
And vendor directory...
Comment #13
pfrenssenThe files you provide look fine to me. The
composer.json
file contains the reference to symfony/yaml but this is not strictly required, it is normally inherited from Coder. But it 100% fine to put it there and you are expected to do it if you use the Yaml component in your own code.The
composer.lock
also looks fine. It contains a reference to symfony/yaml version 3.4.4. I verified this particular release and the file is there and has the correct namespace (ref. v3.4.4/Yaml.php).I noticed that we have very few instances of calling directly into namespaced code, in fact at first glance it seems that this is the only instance. So I have tried it locally in a fresh installation of my project (ref. https://github.com/ec-europa/joinup-dev):
To be 100% sure that this code is actually running as expected I edited the file
AutoAddedKeysSniff.php
and changed the line that calls into namespace to something invalid. It fails as expected:Can you verify that the symfony/yaml package is present in the vendor file? If it is there, maybe you need to rebuild your autoload files, so maybe you can try to run this command?
If this doesn't fix it for you I am not sure how I can help you further. You'll need to start debugging it probably, check why the autoloader is not being loaded, maybe it loads the wrong one?
Comment #14
xpersonas CreditAttribution: xpersonas commentedAwesome.
$ composer dump-autoload
did the trick. Thank you so much. That command wasn't on my radar so I hadn't tried that. I'm all good now!Comment #15
pfrenssenWow! Great news! Glad you have it up and running!
Comment #17
Chi CreditAttribution: Chi commentedThis issue occurs when you have phpcs installed globally because in this case phpcs uses its own autoloader instance which is not aware about Coder dependencies.
Comment #18
slivorezkaSo I got the same bug.
And looks like @Chi is right it something wrong with phpcs installation.
And my solution to fix it just replaced in the command phpcs to ~/.composer/vendor/bin/phpcs
For example:
~/.composer/vendor/bin/phpcs --standard=Drupal /path/to/code
Comment #19
psf_ CreditAttribution: psf_ commentedI have this issue with global installation, but fail DrupalPractice and work Drupal.
Comment #18 work for me, but in my ubuntu the global path is:
~/.config/composer/vendor/bin
My OS version:
Comment #20
sgourebi CreditAttribution: sgourebi commentedsudo ln -s ~/.config/composer/vendor/bin/phpcs /usr/local/bin/phpcs
phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml path/to/module
Comment #21
Meerachandran CreditAttribution: Meerachandran commentedI also have the same problem. Comment #18 worked for me.