Following this article, I'm trying to generate an image from html on Entry Save, but I'm getting an error when trying to push a job GenerateSocialCard to the Craft queue.

I'm using the default Module. Here is the code:

Queue::push(new GenerateSocialCard([
  'elementId' => $element->id 

I have GenerateSocialCard.php under modules/jobs with the GenerateSocialCard class defined:


namespace modules\jobs;

use Craft;
use craft\helpers\App;
use craft\queue\BaseJob;
use Spatie\Browsershot\Browsershot;

class GenerateSocialCard extends BaseJob

    public $elementId;

    public function execute($queue)
        Browsershot::url(getenv('PRIMARY_SITE_URL') . '/x/' . $this->elementId)
            ->windowSize(1200, 675)
            ->save(getcwd() . '/web/img/fakty' . $this->elementId . '.png');

    protected function defaultDescription(): string
        return Craft::t('app', 'Generate the social card');

I'm still getting an error Class "modules\jobs\GenerateSocialCard" not found

Any Ideas?

Thank you!!

Modules folder structure:

  - jobs
    - GenerateSocialCard.php
- Module.php


"autoload": {
   "psr-4": {
     "modules\\": "modules/"
  • Looks like the autoloader can't find the PHP file with the class in it – can you post your directory structure (especially the modules/ folder) and your composer.json (especially the autoload setup)?
    – MoritzLost
    Commented Jun 29, 2023 at 9:29
  • @MoritzLost I edited the question with all the information you requested. Commented Jun 29, 2023 at 11:40
  • Hm, that all looks correct … does the error go away when you run composer dump-autoload?
    – MoritzLost
    Commented Jun 29, 2023 at 12:31
  • @MoritzLost Nope. It didn't help ... I'm still getting the same error. Btw, I was getting Class "modules\GenerateSocialCard" not found, so I tried to add use modules\jobs\GenerateSocialCard;, then I got the Class "modules\jobs\GenerateSocialCard" not found. Commented Jun 29, 2023 at 12:59


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.