sh: symfony-cmd: command not found
Asked Answered
H

5

18

I have downgraded a Symfony 5.2 app template to use Symfony 4.4 in order to allow the use of some libraries that require an older version of Symfony. The problem is that when I do composer install, I get this error near the end of the installation:

sh: symfony-cmd: command not found

It seems that the installations are mostly successful, as my vendor folder is created and populated. But I'm worried about the error.

What does this error mean? How do I fix it?

====

Edit: Here's my composer.json file:

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require": {
        "php": ">=7.4.0",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "ext-json": "*",
        "composer/package-versions-deprecated": "1.11.99.1",
        "cweagans/composer-patches": "^1.7",
        "doctrine/doctrine-bundle": "^2.4",
        "doctrine/doctrine-migrations-bundle": "^3.1",
        "doctrine/orm": "^2.9",
        "phpdocumentor/reflection-docblock": "*",
        "sensio/framework-extra-bundle": "*",
        "symfony/framework-bundle": "4.4.*",
        "symfony/http-client": "*",
        "symfony/intl": "*",
        "symfony/mailer": "*",
        "symfony/mime": "*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/notifier": "*",
        "symfony/process": "*",
        "symfony/property-access": "*",
        "symfony/property-info": "*",
        "symfony/proxy-manager-bridge": "*",
        "symfony/security-bundle": "*",
        "symfony/serializer": "*",
        "symfony/string": "*",
        "symfony/translation": "*",
        "symfony/twig-bundle": "*",
        "symfony/validator": "*",
        "symfony/web-link": "*",
        "symfony/yaml": "*",
        "twig/extra-bundle": "*",
        "twig/twig": "*"
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.4",
        "roave/security-advisories": "dev-master",
        "symfony/browser-kit": "*",
        "symfony/css-selector": "*",
        "symfony/debug-bundle": "*",
        "symfony/maker-bundle": "*",
        "symfony/phpunit-bridge": "*",
        "symfony/stopwatch": "*",
        "symfony/var-dumper": "*",
        "symfony/web-profiler-bundle": "*",
        "vimeo/psalm": "^4.9"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "5.2.*"
        },
        "patches": {
            "symfony/maker-bundle": {
                "Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
            }
        }
    }
}
Hastate answered 29/8, 2021 at 13:0 Comment(0)
M
18

symfony-cmd is a part of Symfony Flex. Your composer.json does not contain any requirement for Flex, so running composer require symfony/flex might resolve that problem.

Magnetism answered 29/8, 2021 at 15:16 Comment(1)
While I ran into some recursive problems with composer require, adding that requirement to the composer.json file was enough to fix the issue. Thanks!Hastate
C
32

For those who have the symfony/flex package installed and are still getting the error, make sure the symfony/flex package is allowed to execute code when running composer.

This is because since Composer 2.2.0 the allow-plugins option adds a layer of security that allows you to restrict which Composer plugins can execute code at startup time.

So make sure you have the appropriate line in the allow-plugins config in your composer.json file

"config": { 
    // other config...

    "allow-plugins": {
        "symfony/flex": true
    }
},
Cherub answered 24/3, 2022 at 9:9 Comment(2)
this did the trick! thanks!Presbyterian
That also did the trick for me. I also had to add "symfony/runtime": true in the list of allowed plugins,Erase
M
18

symfony-cmd is a part of Symfony Flex. Your composer.json does not contain any requirement for Flex, so running composer require symfony/flex might resolve that problem.

Magnetism answered 29/8, 2021 at 15:16 Comment(1)
While I ran into some recursive problems with composer require, adding that requirement to the composer.json file was enough to fix the issue. Thanks!Hastate
L
6

as addition, we just ran into this issue in docker which runs as root. since composer 2.7 plugins are disabled when running as root.

to bypass this check, set the following environment variable:

COMPOSER_ALLOW_SUPERUSER=1

https://github.com/composer/composer/releases/tag/2.7.0

Fixed automatic disabling of plugins when running non-interactive as root

Lineup answered 29/2 at 12:9 Comment(1)
It's important to note that the primary cause of this error is because of running composer as a root user and simply bypassing this with the environment variable, or running as a non-root user is the solution to the majority of those experiencing this issue.Ulmer
E
5

While adding symfony/flex to the project is one solution, keep in mind that Flex is optional. If you want to get rid of the error without installing Flex, simply remove the symfony-cmd command references from your composer.json.

Before:

    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },

After:

    "scripts": {
        "auto-scripts": {},
        "post-install-cmd": [],
        "post-update-cmd": []
    },
Equestrienne answered 16/3, 2022 at 21:29 Comment(0)
S
1

I ran into a special case were an old deploy script added --no-plugins to my composer command. Removing that solved my issue with using deployer v6.

set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');

Apparently you need plugins for flex to work, and I'm assuming since the scripts block has some commands you need that too. So having no script/plugins will break your installation.

Superclass answered 3/12, 2022 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.