External JavaScript libraries missing type: external attribute causing JS aggregation errors

Created on 6 January 2026, 13 days ago

Problem/Motivation

When JavaScript aggregation is enabled (typically on production environments), Drupal throws an exception when trying to optimize the external CDN JavaScript files defined in search_api_typesense.libraries.yml:

Error trying to optimize JavaScript asset: https://cdn.jsdelivr.net/npm/algoliasearch@4.20.0/dist/algoliasearch-lite.umd.js. Only file JavaScript assets can be optimized.

The error occurs in Drupal\Core\Asset\JsOptimizer->optimize() because the optimizer attempts to process external URLs as local files.

Steps to reproduce

1. Enable the search_api_typesense module in Drupal 11.3.1
2. Enable JavaScript aggregation (/admin/config/development/performance)
3. Visit a page that loads the search_api_typesense/instantsearch library
4. Observe the exception in the logs

Proposed resolution

The external JavaScript files in search_api_typesense.libraries.yml need to be marked with type: external attribute:

instantsearch:
    js:
      https://cdn.jsdelivr.net/npm/typesense-instantsearch-adapter@2/dist/typesense-instantsearch-adapter.min.js: { type: external }
      https://cdn.jsdelivr.net/npm/algoliasearch@4.20.0/dist/algoliasearch-lite.umd.js: { type: external }
      https://cdn.jsdelivr.net/npm/instantsearch.js@4.60.0/dist/instantsearch.production.min.js: { type: external }

See: https://www.drupal.org/docs/develop/creating-modules/adding-assets-css-j...

Remaining tasks

- Apply the fix to search_api_typesense.libraries.yml
- Review and commit

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇷🇸Serbia norbert-goco Subotica

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024