0

I am trying to integrate a React module into Drupal, my first time trying to do such a thing. I have developed this module locally and it runs fine. When I upload it to my server, I get the following error. What could be the difference that is causing this error and how can I fix it? I know there is probably a lot different between my local env and the server env, so any help with what it could be is appreciated.

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Core\Asset\AttachedAssets::setLibraries() must be of the type array, 
string given, called in /var/www/html/web/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php 
on line 141 in 
Drupal\Core\Asset\AttachedAssets->setLibraries() (line 52 of core/lib/Drupal/Core/Asset/AttachedAssets.php). 

/modules/custom/react-crud/react_crud.libraries.yml

react-basic:
  js:
    dist/index.js: { preprocess: false }

/modules/custom/react_crud/src/Controller/ReactCRUDBlock.php

<?php

namespace Drupal\react_crud\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\react_crud\Controller\ReactCRUDController;


/**
 * Provides a 'ReactCRUDBlock' block.
 *
 * @Block(
 *  id = "react_crud_block",
 *  admin_label = @Translation("React CRUD block"),
 * )
 */
class ReactCRUDBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    $build = [];
    $build['#attached']['library'][] = 'react_crud/react-basic';
    $build['react_crud_block'] = [
      '#markup' => '<div id="root"></div>'
    ];
    return $build;
  }
}

/modules/custom/react_crud/src/Controller/ReactCRUDController.php

<?php

namespace Drupal\react_crud\Controller;

//use Drupal\examples\Utility\DescriptionTemplateTrait;

/**
 * Controller routines for block example routes.
 */
class ReactCRUDController {
/**
   * {@inheritdoc}
   */
  public function example() {
    $build = [];
    $build['#attached']['library'][] = 'react_crud/react-basic';
    $build['react_crud_block'] = [
      '#markup' => '<div id="root"></div>'
    ];
    return [];
  }
}
2
  • 1
    I can't tell where there is an error in your code, but the error occurs in an Ajax response. Since you are implementing React your module probably doesn't use Ajax. So look for a different module which might be installed in prod env. For example BigPipe which lazily loads blocks through Ajax.
    – 4uk4
    Commented Dec 22, 2020 at 21:16
  • @4k4 Thank you for the reply. It was the BigPipe module that was causing the issue. I uninstalled it and my React module works now. Much appreciated!
    – jbreslow
    Commented Dec 22, 2020 at 21:30

0

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.