Fix AMD Loader issue for jQuery Plugins

 Fix AMD Loader issue for jQuery libraries

Prerequisites

Custom portlet has included jQuery library, sample:
com.liferay.portlet.header-portlet-javascript=/js/jstree.js"

Error


Javascript error during loading portlet:
 

Fix

Modify the library source:

(function (factory) {
    "use strict";
    if (typeof define === 'function' && define.amd) {
        define(['jquery'], factory);
    }
    else if(typeof module !== 'undefined' && module.exports) {
        module.exports = factory(require('jquery'));
    }
    else {
        factory(jQuery);
    }
}(function ($, undefined) {
...
 

Replace the 'define.amd' with false to fix the AMD loading issue.
 
P.S.
Related article for including jQuery into theme:
https://lifedev-solutions.blogspot.com/2019/10/include-jquery-plugin-into-theme.html

Comments

Popular posts from this blog

Liferay Search Container Example

Liferay DXP - max upload file size

Liferay Keycloak integration