Drupal "The website encountered an unexpected error" (stale cache) in CI
Drupal compiles services and routes into a cached container. After updating code, modules, or config in CI, the old cache can reference a class or service that changed, and Drupal aborts the request with a generic unexpected-error message until you rebuild.
What this error means
A page render or post-deploy check fails with "The website encountered an unexpected error. Please try again later." and the log shows a "ServiceNotFoundException" or "Class ... not found" after an update.
The website encountered an unexpected error. Please try again later.
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
The service "my_module.manager" has a dependency on a non-existent service "old.service".Common causes
A stale compiled container after a code change
The cached service container still references services or classes that an update renamed or removed, so resolution fails at runtime.
Caches not rebuilt after enabling or updating modules
New routes, plugins, or services are not picked up until the cache is cleared, so requests hit the old definitions.
How to fix it
Rebuild caches after every update
- Run
drush cache:rebuildafter composer install anddrush updatedb. - Order it before any request-serving check.
- Re-run the failing page to confirm the new container loads.
./vendor/bin/drush updatedb -y
./vendor/bin/drush cache:rebuildClear caches before config import
Rebuild so the container matches current code before importing configuration that depends on new services.
./vendor/bin/drush cr && ./vendor/bin/drush config:import -yHow to prevent it
- Always run
drush cache:rebuildafter deploy-time updates. - Sequence updatedb, cache rebuild, then config import.
- Treat the compiled container as disposable across deploys.