After upgrading Drupal 9 to Drupal 10.2.4 "Uncaught SyntaxError: Unexpected token '<'" in js aggregation

Created on 31 March 2024, 3 months ago
Updated 1 April 2024, 3 months ago

Problem/Motivation

After upgradation from Drupal 9 to 10.2.4 the console is showing one error "Uncaught SyntaxError: Unexpected token '<' (at js_c54m2Mp9GtZPEHSrtTz39K8evrLNp2gTuD-rMNtpoo8.js?scope=header&delta=0&language=en&theme=claro&include=eJx9UFtywzAIvJBsnSEn8ciYcWhkoQHkND195Yc8TT_yBcsuuwzAyfDbSoh-kpJD7OGadJHSQx2woE8sS4j0gw5iEPZz5LEq1F5VNB-a0yCA0Yr7sjNeBy2jkqH_0w9fulNPHBVlJThYUHX6UsOleR3ozR44xpAVnd5ZDIpd2hO7ecoycEKTouY31DXUhUw1meMYxJ_VlXpDM9n6nuoPtgPLpini4NOTmkuYFkrDifaqLWE3fBdclAniB6q_84pCNS3Z_8N7VAgZb9uyG2keMmX0rfkFhdi6kQ:1:1)"

Steps to reproduce

When CSS/JS aggregation is enabled it is showing above mentioned error and after clicking on the JS file there is HTML wrapper added in JS file

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>

Proposed resolution

After immediate reload the error disappear from console and JS aggregated file removes above HTML wrapper line and site works fine.

Remaining tasks

User interface changes

It impacts on both admin ui as well as custom theme UI & home page of website. For eg: /admin/modules did'nt show "INSTALL" button and also the searchign any module didn't work in same page etc. <

I have tried some solutions like uninstalling big pipe module, re-checked all custom js file but nothing helped much.

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

1.0

Component
Asset library 

Last updated 5 days ago

No maintainer
Created by

🇮🇳India pratishjha

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

Comments & Activities

  • Issue created by @pratishjha
  • Status changed to Active 3 months ago
  • 🇳🇿New Zealand quietone New Zealand

    Reformat issue summary for readability as tag per the tag guidelines..

  • Status changed to Postponed: needs info 3 months ago
  • 🇬🇧United Kingdom catch

    This needs some more information, it looks like something is injecting the HTML into the aggregate response, definitely doesn't come from Drupal core.

    Is this on production? If so do you have a local version of your site to compare against?

    Which contrib modules do you have enabled?

    What hosting environment are you using?

    Can you double check that the HTML isn't in the files written to disk - it sounds from your report like it isn't, they're usually in sites/default/files/css and sites/default/files/js.

  • 🇮🇳India pratishjha

    Just now I found the root cause, indeed it is due to the contrib/custom module.
    A contrib module https://www.drupal.org/project/relative_to_absolute_url is used (this module is not available for D10, it is usded in custom by fixing deprecations for drupal 10 & PHP8.2) which converts all relative URLs to absolute. (Needed for this site).
    I have installed module https://www.drupal.org/project/rel_to_abs but it not convert relative URLs to absolute.
    Can you suggest any fix or any way to convert URLs from relative to absolute.

  • 🇺🇸United States nicxvan

    That module doesn't even have a Drupal 9 release.

    It is seeking a new maintainer, you could request maintainership and if the owner does not respond use this process:

    https://www.drupal.org/docs/develop/managing-a-drupalorg-theme-module-or...

    Once you have maintainership you can update for Drupal 9 / 10

  • 🇺🇸United States nicxvan
  • 🇮🇳India pratishjha

    The module was working fine for Drupal 9 (with some small deprecations fixes & using it in custom), but in Drupal 10 it adds extra HTML tags. I will request for maintainership.
    Meanwhile is there any module or hook/code/patch to convert all URLs to absolute?
    It will be a great help if you could provide any solutions.

  • Status changed to Active 3 months ago
  • 🇬🇧United Kingdom catch

    Moving this to the project since I couldn't see an existing bug report there.

    @pratishjha for alternative modules try asking in #support in Drupal slack.

Production build 0.69.0 2024