Skip to content

composer install --no-dev --optimize-autoloader return class not found. #36604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Guervyl opened this issue Apr 28, 2020 · 8 comments
Closed

Comments

@Guervyl
Copy link

Guervyl commented Apr 28, 2020

Symfony version(s) affected: 5.0

Description
I am following this guide: https://symfony.com/doc/current/deployment.html#common-post-deployment-tasks.

I'm on a linux system. Centos 7.

I uploaded my source code on the server. I installed the dependencies on the server. I ran composer dump-env prod. I ran composer require symfony/dotenv. I set APP_ENV=prod in the .env. Note I don't have .env.local but .env.local.php. I ran export APP_ENV=prod then export SYMFONY_ENV=prod. And finally composer install --no-dev --optimize-autoloader.

The output of composer is:

Loading composer repositories with package information
Installing dependencies from lock file
Package operations: 0 installs, 0 updates, 23 removals

  • Removing zendframework/zend-eventmanager (3.2.1)
  • Removing zendframework/zend-code (3.4.1)
  • Removing symfony/stopwatch (v5.0.7)
  • Removing symfony/orm-pack (v1.0.8)
  • Removing symfony/maker-bundle (v1.15.0)
  • Removing symfony/doctrine-bridge (v5.0.7)
  • Removing ocramius/proxy-manager (2.2.3)
  • Removing ocramius/package-versions (1.5.1)
  • Removing nikic/php-parser (v4.3.0)
  • Removing jdorn/sql-formatter (v1.2.17)
  • Removing doctrine/reflection (1.2.1)
  • Removing doctrine/persistence (1.3.7)
  • Removing doctrine/orm (v2.7.2)
  • Removing doctrine/migrations (2.2.1)
  • Removing doctrine/instantiator (1.3.0)
  • Removing doctrine/inflector (1.3.1)
  • Removing doctrine/event-manager (1.1.0)
  • Removing doctrine/doctrine-migrations-bundle (2.1.2)
  • Removing doctrine/doctrine-bundle (2.0.7)
  • Removing doctrine/dbal (v2.10.1)
  • Removing doctrine/common (2.12.0)
  • Removing doctrine/collections (1.6.4)
  • Removing doctrine/cache (1.10.0)
    Generating optimized autoload files
    ocramius/package-versions: Package not found (probably scheduled for removal); generation of version class skipped.
    Executing script cache:clear [KO]
    [KO]
    Script cache:clear returned with error code 255
    !!
    !! Fatal error: Uncaught Error: Class 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle' not found in /home/trantkwr/public_html/src/Kernel.php:23
    !! Stack trace:
    !! #0 /home/trantkwr/public_html/vendor/symfony/http-kernel/Kernel.php(369): App\Kernel->registerBundles()
    !! Untitled #1 /home/trantkwr/public_html/vendor/symfony/http-kernel/Kernel.php(123): Symfony\Component\HttpKernel\Kernel->initializeBundles()
    !! Renaming "Entities" to "Entity" #2 /home/trantkwr/public_html/vendor/symfony/framework-bundle/Console/Application.php(169): Symfony\Component\HttpKernel\Kernel->boot()
    !! Untitled #3 /home/trantkwr/public_html/vendor/symfony/framework-bundle/Console/Application.php(75): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
    !! Same change for mapping files #4 /home/trantkwr/public_html/vendor/symfony/console/Application.php(140): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    !! Using ORM and MongoDB both in the same bundle. #5 /home/trantkwr/public_html/bin/console(42): Symfony\Component\Console\Application->run(Object(Symfony\Compo in /home/trantkwr/public_html/src/Kernel.php on line 23
    !!
    Script @auto-scripts was called via post-install-cmd
@xabbuh
Copy link
Member

xabbuh commented Apr 28, 2020

Can you share your composer.json file?

@Guervyl
Copy link
Author

Guervyl commented Apr 28, 2020

Can you share your composer.json file?

Yes.

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.2.5",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "doctrine/annotations": "^1.10",
        "google/apiclient": "2.0",
        "sensio/framework-extra-bundle": "^5.5",
        "symfony/console": "5.0.*",
        "symfony/dotenv": "5.0.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "5.0.*",
        "symfony/framework-bundle": "5.0.*",
        "symfony/security-bundle": "5.0.*",
        "symfony/serializer-pack": "^1.0",
        "symfony/string": "5.0.*",
        "symfony/translation": "5.0.*",
        "symfony/validator": "5.0.*",
        "symfony/yaml": "5.0.*"
    },
    "require-dev": {
        "symfony/maker-bundle": "^1.15"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "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.0.*"
        }
    }
}

@xabbuh
Copy link
Member

xabbuh commented Apr 28, 2020

Well, your kernel still tries to load the DoctrineBundle (for example in config/bundles.php) while you didn't list the doctrine/doctrine-bundle package in your composer.json file.

@Guervyl
Copy link
Author

Guervyl commented Apr 28, 2020

I didn't do anything. It's just a Symfony project from composer create-project. And I installed the Doctrine bundle running
composer require symfony/orm-pack composer require --dev symfony/maker-bundle And the project is running fine in Dev and also running fine in APP_ENV=prod.

I just follow this doc to install Doctrine

How can I fix it?

@xabbuh
Copy link
Member

xabbuh commented Apr 28, 2020

Looks like somehow the ORM pack was removed. Does running composer require symfony/orm-pack again help?

@Guervyl
Copy link
Author

Guervyl commented Apr 28, 2020

composer require symfony/orm-pack

I don't know why it was removed from the composer.json. But after running composer require symfony/orm-pack It just put it back:

composer require symfony/orm-pack
Using version ^1.0 for symfony/orm-pack
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.0.*"
Nothing to install or update
Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.
Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
Writing lock file
Generating autoload files
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
45 packages you are using are looking for funding.
Use the composer fund command to find out more!
Executing script cache:clear [OK]
Executing script assets:install public [OK]

Then composer install --no-dev --optimize-autoloader works fine:

composer install --no-dev --optimize-autoloader
Loading composer repositories with package information
Installing dependencies from lock file
Package operations: 0 installs, 0 updates, 2 removals

  • Removing symfony/maker-bundle (v1.15.0)
  • Removing nikic/php-parser (v4.3.0)
    Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.
    Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
    Generating optimized autoload files
    ocramius/package-versions: Generating version class...
    ocramius/package-versions: ...done generating version class
    44 packages you are using are looking for funding.
    Use the composer fund command to find out more!
    Executing script cache:clear [OK]
    Executing script assets:install public [OK]

Thanks for your support :)

@Guervyl Guervyl closed this as completed Apr 28, 2020
@xabbuh
Copy link
Member

xabbuh commented Apr 29, 2020

Without actually knowing what output your received before or what might have happened additionally that's indeed hard to say. :) But I am glad that you managed to resolve your issue.

@dunglehome
Copy link

dunglehome commented Jan 30, 2024

Hello,

In short if you have issue of missing package / (class not found) after running the above command -> the solution is just add that package to section "require" (this is production sections) or run "composer require symfony/yourmissingpackageorclass" that will fix it.

A late one, but thank you for sharing. I found out that when going into production, there are some packages you have to move from dev to prod for example:

in your composer.json

"require": { package-from-dev:version, package2:version, package3:version}
"require-dev": { package2:version, package3:version}

image

this post helps me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants