Error when there are installed modules with invalid library definitions

Created on 6 December 2023, 7 months ago
Updated 8 December 2023, 7 months ago

Problem/Motivation

There was an issue with the Flmngr file manager module v. 8.x-2.12 - its installation turned Drupal into an unusable state. Even pages of the dashboard returned error 500 with the message:

Your question: When using composer require 'drupal/flmngr:^2.12' and installing on my Drupal 10 instance I receive the following error messages: [05-Dec-2023 12:54:21 America/Chicago] Uncaught PHP Exception Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException: "Incomplete library definition for definition 'flmngr' in extension 'flmngr'" at /home/[webroot]/public_html/[sitename]/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php line 135

(in new 8.x-2.13 the "flmngr.libraries.yml" file was deleted, so there is no such problem after 2.12).

First of all, there was a thought that the format of libraries file was incorrect, but it was fine:

flmngr:
  version: 1.x

Googling showed similar problems with other modules + CSP module: [1] β†’ [2] β†’
And "remove YML file" as a recommendation.

Having a libraries.yml file without any CSS/JS declared is not an error, so I guess this is a bug of the CSP module.

It is not too hard to remove a YML file from a module, but nobody knows that it will be a problem when installing a specific plugin (SCP), so this is a pitfall for all Drupal module developers and module users.

Steps to reproduce

Version is important, 2.12 does not have a workaround

composer require 'drupal/flmngr:^2.12'
composer require 'drupal/csp:^1.22'

Then enable both plugins on the Extend page.
Now a website is unusable.

Proposed resolution

Please consider fixing processing "module.libraries.yml" files with no CSS/JS libraries declared. Such processing should not raise an exception and cause a website to always return a 500 HTTP error.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @dmitriy-komarov
  • πŸ‡¨πŸ‡¦Canada gapple

    Thanks for the report - I'll really need to look at this one since CSP now has its own library with no JS or CSS files 😰 (though it hasn't caused errors so far 🀞).

    It might be sufficient to just add some exception handling when CSP is scanning for all libraries so that it ignores invalid definitions - CSP is kind of a canary because it loads all libraries even if they are unused (which is fine and valid in certain cases)

  • πŸ‡¨πŸ‡¦Canada gapple

    So CSP's own library is safe, since it has a dependency, and a library must only define one of css, js, drupalSettings, or dependencies.

    There are also currently a few other errors that could occur in library definitions (if header is not a boolean value, a remote library does not define a license, or a JavaScript file is given a positive weight), but an unused and incomplete definition is probably the most likely to happen. If CSP skips and logs the exception, it would still be thrown later if any library from the module is actually used and the parsing is attempted again.

    • gapple β†’ committed e7acfc3f on 8.x-1.x
      Issue #3406513: Error when there are installed modules with invalid...
  • Status changed to Fixed 7 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024