Not sure if it's just me but I'm getting the below fatal error when clearing cache with both drush 8.2.2 and drupal console 1.8.0

$ drush cr

PHP Fatal error:  Uncaught Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php:270
Stack trace:
#0 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171): Drupal\Component\DependencyInjection\Container->createService(Array, 'serializer.norm...')
#1 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(480): Drupal\Component\DependencyInjection\Container->get('serializer.norm...', 1)
#2 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(508): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#3 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(230): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#4 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171): Drupal\Component\DependencyInjection\Container->createService(Array,  in /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 270
Drush command terminated abnormally due to an unrecoverable error.                                                       [error]
Error: Uncaught Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not
found in /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php:270
Stack trace:
#0 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171):
Drupal\Component\DependencyInjection\Container->createService(Array, 'serializer.norm...')
#1 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(480):
Drupal\Component\DependencyInjection\Container->get('serializer.norm...', 1)
#2 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(508):
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#3 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(230):
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#4 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171):
Drupal\Component\DependencyInjection\Container->createService(Array,  in
/app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php, line 270
$ drupal cr all

PHP Fatal error:  Uncaught Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php:270
Stack trace:
#0 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171): Drupal\Component\DependencyInjection\Container->createService(Array, 'serializer.norm...')
#1 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(480): Drupal\Component\DependencyInjection\Container->get('serializer.norm...', 1)
#2 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(508): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#3 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(230): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#4 /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171): Drupal\Component\DependencyInjection\Container->createService(Array,  in /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 270

Fatal error: Uncaught Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 270

Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 270

Call Stack:
    0.0036     359448   1. {main}() /app/vendor/drupal/console/bin/drupal:0
    0.0062     378184   2. require('/app/vendor/drupal/console/bin/drupal.php') /app/vendor/drupal/console/bin/drupal:4
   12.6682   53112312   3. Drupal\Console\Application->run() /app/vendor/drupal/console/bin/drupal.php:89
   12.6830   53288608   4. Drupal\Console\Application->doRun() /app/vendor/symfony/console/Application.php:148
   18.6623   58689872   5. Drupal\Console\Application->doRun() /app/vendor/drupal/console/src/Application.php:64
   20.1211   75333976   6. Drupal\Console\Application->doRun() /app/vendor/drupal/console-core/src/Application.php:185
   20.1255   75336400   7. Drupal\Console\Application->doRunCommand() /app/vendor/symfony/console/Application.php:255

I debugged a bit and reckon that Composer Classloader adds 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' into its missingClasses before Drupal calls addPsr4() to add the container.namespaces into class loader. An interesting point is that clearing cache via admin UI doesn't cause the fatal error and JSON:API Extras still works with its normalizers and field enhancers.

I am using Composer version 1.8.4 2019-02-11 10:52:10, Drush 8.2.2, Drupal Console 1.8.0, Drupal 8.6.12, and JSON:API 8.x-2.4. Is there any other requirement that I'm missing?

Comments

sonnykt created an issue. See original summary.

jungle’s picture

Title: JSON:API Extras 3.5 causes fatal error when clearing cache with drush/console due to impostor normalizers » JSON:API Extras 3.6 causes fatal error when clearing cache with drush/console due to impostor normalizers
Version: 8.x-3.5 » 8.x-3.6

It's happened on one of my sites.

  • Drupal Core: 8.7.1
  • jsonapi_extras: 8.3.6
  • Drupal Console version 1.8.0
  • Drush Commandline Tool 9.6.2

$ cd /var/www/html/web && drush cr
Fatal error: Uncaught Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 277

Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 277

Call Stack:
    0.0002     392720   1. {main}() /var/www/html/vendor/drush/drush/drush:0
    0.0026     393728   2. require('/var/www/html/vendor/drush/drush/drush.php') /var/www/html/vendor/drush/drush/drush:4
    0.0552     892016   3. Drush\Runtime\Runtime->run() /var/www/html/vendor/drush/drush/drush.php:72
    0.0559     897336   4. Drush\Runtime\Runtime->doRun() /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php:49
    0.4565    3626064   5. Drush\Application->run() /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php:118
    0.4569    3626952   6. Drush\Application->doRun() /var/www/html/vendor/symfony/console/Application.php:148
    0.4573    3627520   7. Drush\Application->doRunCommand() /var/www/html/vendor/symfony/console/Application.php:255

 [warning] Drush command terminated abnormally. Check for an exit() in your Drupal site.
$ cd /var/www/html/web && drupal cr

 Rebuilding cache(s), wait a moment please.

Fatal error: Uncaught Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 277

Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 277

Call Stack:
    0.0002     392752   1. {main}() /var/www/html/vendor/drupal/console/bin/drupal:0
    0.0006     393696   2. require('/var/www/html/vendor/drupal/console/bin/drupal.php') /var/www/html/vendor/drupal/console/bin/drupal:4
    9.1861   24041704   3. Drupal\Console\Application->run() /var/www/html/vendor/drupal/console/bin/drupal.php:89
    9.1905   24124984   4. Drupal\Console\Application->doRun() /var/www/html/vendor/symfony/console/Application.php:148
   11.3954   29979440   5. Drupal\Console\Application->doRun() /var/www/html/vendor/drupal/console/src/Application.php:64
   14.8712   78111008   6. Drupal\Console\Application->doRun() /var/www/html/vendor/drupal/console-core/src/Application.php:185
   14.8714   78112072   7. Drupal\Console\Application->doRunCommand() /var/www/html/vendor/symfony/console/Application.php:255
bander2’s picture

StatusFileSize
new7.96 KB

I got the same error when trying to install jsonapi_extras on a D8.7.1 site through the UI.

igarbla’s picture

Same here on a fresh installation.

Installing the module via drupal moi jsonapi_extras throws an error

[ERROR] Class Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor does not exist

although the module seems to be installed, the settings doesn't appear.

Installing the module via the UI throws an error on screen The website encountered an unexpected error. Please try again later. If you try to navigate to the settings the same error appears, then if you clear caches via the UI, everything seems to work.

Rebuilding cache via drupal/drush thows

PHP Fatal error: Uncaught Error: Class 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' not found in /home/igarcia/Workshop/Sandbox/Drupal/drupal8-entity/web/core/lib/Drupal/Component/DependencyInjection/Container.php:277

esolitos’s picture

Isn't this module already integrated in 8.7,x?

igarbla’s picture

This is jsonapi_extras. The one integrated in 8.7.x is jsonapi.

christian.marx’s picture

Solution:
- Create directory '/mdules/contrib/jsonapi/src/Normalizer/ImpostorFrom'
- Copy files from 'modul/contrib/jsonapi_extras/src-impostor-normalizers' to just created directory

psf_’s picture

markhalliwell’s picture

So, this module is doing some weird stuff with namespaces (which doesn't follow PSR-4 btw):
https://git.drupalcode.org/project/jsonapi_extras/blob/8.x-3.x/src/Jsona...

psf_’s picture

A colleague found that the module webprofile break that. We remove it and all it's working now...

e0ipso’s picture

A colleague found that the module webprofile break that. We remove it and all it's working now...

Thanks for looping back onto this @psf_. Did she/he have confirmation of why it was interacting with the webprofile module?

sonnykt’s picture

My sites don't have the module webprofiler enabled.

As per my debug, it may be something with Composer Classloader instead.

Composer Classloader adds 'Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras\FieldItemNormalizerImpostor' into its missingClasses before Drupal calls addPsr4() to add the container.namespaces into class loader.

jncruces’s picture

Hi,

I found the problem with WebProfiler helping @psf_.

But i don't think that the problem is related with WebProfiler... I think that the problem is an overload on the system. On our system the module that has produced the overload was Webprofiler because it was configured to store al profilling data in the database and the webprofiler table was very large.

I think that the method used to overwrite the services provided by JSONAPI using alterations of namespaces are not correct and produces this incongruences loading services. I know that a system overloaded is not correct but I think that any system can be overloaded sometimes because low server resources or not enough resources for a big amount of people using the site. A site overloaded must work... slow but must work.

All the services must be decorated normally without apply "impostor" namespaces on JSONAPI Extras. The solution is remove the enforce of JSONAPI namespace.

Greetings.

e0ipso’s picture

The solution is remove the enforce of JSONAPI namespace.

I agree. However that was introduced (temporarily) for good reason. We'd love to get a helping hand into reaching that eventual goal. Any chance you & your team can help out with it?

e0ipso’s picture

Title: JSON:API Extras 3.6 causes fatal error when clearing cache with drush/console due to impostor normalizers » Fatal error with impostor normalizers when there is an autowired service

I've seen that this is triggered when some unrelated service uses autowire: true in the service definition.

sonnykt’s picture

My sites have only one service enabled with autowire: true which is from permission_by_term module. I'll test further with the module disabled to confirm.

e0ipso’s picture

Thanks @sonnykt. It's good to see that the hypothesis seems to hold in your case.

j1mb0b’s picture

After reading Symfony docs I found:

https://symfony.com/doc/current/service_container/synthetic_services.html

Looking at this, the key part: "Services that are set at runtime are called synthetic services. This service has to be configured so the container knows the service exists during compilation (otherwise, services depending on kernel will get a "service does not exist" error).

Would it help to implement a synthetic service here?

j1mb0b’s picture

I found a workaround for my implementation, in the Container.php createService method there is an opportunity to require a file during the service definition creation.

See patch.

j1mb0b’s picture

Status: Active » Needs review

  • e0ipso committed 56286c5 on 8.x-3.x authored by j1mb0b
    Issue #3045087 by j1mb0b, bander2, e0ipso, sonnykt, psf_, igarbla, Wim...
e0ipso’s picture

Status: Needs review » Fixed

Works as expected. Thanks!

patpluspun’s picture

Works for me when enabling webprofiler module. Thanks j1mb0b!

sonnykt’s picture

Confirming that I no longer get the issue with this fix.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.