Search

Mar 28, 2023

Magento2: Uncaught SyntaxError: Unexpected token const error in Admin panel

 We are using Magento 2.4.4-p2 on STAGING site. We got the JS error on admin page:
+ Uncaught SyntaxError: Unexpected token 'const' at tab.min.js and collapse.min.js
+ Uncaught TypeError: $(...).filter(...).collapse is not a function.

Reference: 


SOLUTION FOR MAGENTO CLOUD (NOT WORK):

1. Update ece-tools
composer update magento/ece-tools --with-dependencies

2. Add the patch on magento.env.yaml and pushed to cloud site

stage: 
  build:
    QUALITY_PATCHES:
      - MDVA-44887



SOLUTION 2:

Follow the below patch

diff --git a/lib/web/jquery/bootstrap/collapse.js b/lib/web/jquery/bootstrap/collapse.js
index 95e28cec248..5a978bcfafb 100644
--- a/lib/web/jquery/bootstrap/collapse.js
+++ b/lib/web/jquery/bootstrap/collapse.js
@@ -32,7 +32,7 @@ define([
     const VERSION = '5.1.3'
     const NAME = 'collapse'
     const DATA_KEY = 'bs.collapse'
-    const EVENT_KEY = `.${DATA_KEY}`
+    const EVENT_KEY = `.${DATA_KEY}`;
     const DATA_API_KEY = '.data-api'
 
     const Default = {
@@ -45,17 +45,17 @@ define([
         parent: '(null|element)'
     }
 
-    const EVENT_SHOW = `show${EVENT_KEY}`
-    const EVENT_SHOWN = `shown${EVENT_KEY}`
-    const EVENT_HIDE = `hide${EVENT_KEY}`
-    const EVENT_HIDDEN = `hidden${EVENT_KEY}`
-    const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
+    const EVENT_SHOW = `show${EVENT_KEY}`;
+    const EVENT_SHOWN = `shown${EVENT_KEY}`;
+    const EVENT_HIDE = `hide${EVENT_KEY}`;
+    const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
+    const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
 
     const CLASS_NAME_SHOW = 'show'
     const CLASS_NAME_COLLAPSE = 'collapse'
     const CLASS_NAME_COLLAPSING = 'collapsing'
     const CLASS_NAME_COLLAPSED = 'collapsed'
-    const CLASS_NAME_DEEPER_CHILDREN = `:scope .${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`
+    const CLASS_NAME_DEEPER_CHILDREN = `:scope .${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`;
     const CLASS_NAME_HORIZONTAL = 'collapse-horizontal'
 
     const WIDTH = 'width'
@@ -204,10 +204,10 @@ define([
         }
 
         const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
-        const scrollSize = `scroll${capitalizedDimension}`
+        const scrollSize = `scroll${capitalizedDimension}`;
 
         this._queueCallback(complete, this._element, true)
-        this._element.style[dimension] = `${this._element[scrollSize]}px`
+        this._element.style[dimension] = `${this._element[scrollSize]}px`;
     }
 
     Collapse.prototype.hide = function() {
@@ -222,7 +222,7 @@ define([
 
         const dimension = this._getDimension()
 
-        this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`
+        this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`;
 
         reflow(this._element)
 
diff --git a/lib/web/jquery/bootstrap/tab.js b/lib/web/jquery/bootstrap/tab.js
index 928f8de3f37..9805d0b0123 100644
--- a/lib/web/jquery/bootstrap/tab.js
+++ b/lib/web/jquery/bootstrap/tab.js
@@ -28,14 +28,14 @@ define([
     const VERSION = '5.1.3'
     const NAME = 'tab'
     const DATA_KEY = 'bs.tab'
-    const EVENT_KEY = `.${DATA_KEY}`
+    const EVENT_KEY = `.${DATA_KEY}`;
     const DATA_API_KEY = '.data-api'
 
-    const EVENT_HIDE = `hide${EVENT_KEY}`
-    const EVENT_HIDDEN = `hidden${EVENT_KEY}`
-    const EVENT_SHOW = `show${EVENT_KEY}`
-    const EVENT_SHOWN = `shown${EVENT_KEY}`
-    const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
+    const EVENT_HIDE = `hide${EVENT_KEY}`;
+    const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
+    const EVENT_SHOW = `show${EVENT_KEY}`;
+    const EVENT_SHOWN = `shown${EVENT_KEY}`;
+    const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
 
     const CLASS_NAME_DROPDOWN_MENU = 'dropdown-menu'
     const CLASS_NAME_ACTIVE = 'active'

No comments:

Post a Comment