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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

norbert-goco created an issue. See original summary.

lussoluca made their first commit to this issue’s fork.

lussoluca’s picture

Status: Active » Needs review
Issue tags: +GlobalContributionWeekend2026

emanuelrighetto made their first commit to this issue’s fork.

  • lussoluca committed 939fd468 on 1.0.x
    fix: #3565794 External JavaScript libraries missing type: external...
lussoluca’s picture

Status: Needs review » Fixed

Committed and merged to 1.0.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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