- Issue created by @poonam11210
Drupal 10.2 is no longer supported. The best advice I can give is to try with a supported release. Additionally, there could be a coding problem with a custom module in the site.
Custom module working as expected in local and other higher environment. @cilefen, have you encountered similar error any time?
No. I suggest you search the Internet for "Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container".
Already search and applied but it didn't helped. Hence created a new issue if I can get any relevant help.
Unfortunately nobody reading this will understand what "emp login" means because I don't know what that is. Is it part of the problem?
Also, as I mentioned above, Drupal 10.2 is not supported here. Upgrade to a supported release. It's possible this has been fixed.
- ๐ฎ๐ณIndia vandanasom.123
The error ContainerNotInitializedException occurs because the container is being accessed before it's fully initialized in Drupal.
If your custom module or the empowerid integration is trying to access Drupal services (\Drupal::service(), \Drupal::entityTypeManager()) too early (before the container is fully initialized), this error will occur.
Ensure youโre not calling services in hook_enable(), hook_install(), or any code that runs too early in the lifecycle.
Fix:
1. Use Dependency Injection in your custom module instead of directly calling \Drupal::service() wherever possible.
2. Make sure you're not accessing services before Drupal is fully bootstrapped (e.g., not in hook_enable()).
3. Clear cache Correct, I am using \Drupal::service however I wonder why it is working in one environment and not in another environment. Does it depends on PHP version as well? I am not using hook_install or hook_enable anywhere in custom module.
I have gone through below threads as well.
https://www.drupal.org/project/drupal/issues/3420704 ๐ container not initialized yet Active
https://www.drupal.org/project/upgrade_status/issues/3221550 ๐ PHP Fatal error: ContainerNotInitializedException thrown while calling __toString on a TranslatableMarkup Postponed: needs info #7 says module_load_include()
need to be replaced it with \Drupal::moduleHandler()->loadInclude()
I am trying these solution.
Thanks for the help.