I recently searched a lot on use of non-amd jquery code with requirejs but couldn't find a proper way to do it.

To be more specific, I want to use pana-accordion.js found at below mentioned url.


But the problem is that it is not amd aware and nor it exports anything out of it.So far I have created my custom.phtml and called it on homepage through admin area.Below is my custom.phtml

<div class="pana-accordion" id="accordion">
  <div class="pana-accordion-wrap">
    <div class="pana-accordion-item" style="background-color: #F44336"><img width="500" height="300" src="https://unsplash.it/500/300?image=57" /></div>
    <div class="pana-accordion-item" style="background-color: #2196F3"><img width="500" height="300" src="https://unsplash.it/500/300?image=49" /></div>
    <div class="pana-accordion-item" style="background-color: #4CAF50"><img width="500" height="300" src="https://unsplash.it/500/300?image=39" /></div>
    <div class="pana-accordion-item" style="background-color: #FF9800"><img width="500" height="300" src="https://unsplash.it/500/300?image=29" /></div>

<script type="text/javascript">
    require(['jquery','panaaccordion'],function($, accordion) {
                    id: 'accordion',

And Here is configuration for pana-accordion.js javascript module in requirejs-config.js

var config = {
    'map': {
        '*': {
            'panaaccordion': 'js/pana-accordion'
    'shim': {
        'panaaccordion': {
            deps: ['jquery'],
            exports: 'accordion'

Below is some code lines for pana-acordion plugin

var accordion= {
    init: function(options){
        var that=this;
        options = $.extend(true,{
            expandWidth: 500,
            itemWidth: 100,
            extpand: 0,
            autoPlay: true,
            delay: 3000,
            animateTime: 400,
            borderWidth: 1,
            autoPlay: true,
            deviator: 30,

As you can see, it doesn't wrap code inside define() nor it exports or return anything.Rather accordion object is declared globally.

So far I have following questions (those marked as bold sorry for bad formatting but I am trying to improve it).

If I wrap the code inside define like below,

            //pana-accordion plugin code

Still, there is an error in console that says Uncaught TypeError: Cannot read property 'init' of undefined even though I created exports entry in shim configuration. But error resolves when I finally write return statement after accordion object.

return accordion;

What is purpose of using shim if we have to manually write return statement from plugin for object for example?

Second, Do I have to write whole path for shim configuration? If I map alias panaaccordion for file located at 'js/pana-accordion', still I have to use 'js/pana-accordion' for shim configuration otherwise there are some loading order issues.

Third- Can I use such non-amd plugins with requirejs without modifying a single line from them?? If yes, How?

1 Answer 1


Magento already have accordion in lib you can take a look at here https://devdocs.magento.com/guides/v2.3/javascript-dev-guide/widgets/widget_accordion.html
It's ready to use and full compatible for magento. You can extend it and customize to your widget. But if you need integrate your lib you can do your way like above with need setup shim and depend config. Also you will need define wrap your plugin Lastly I don't think you can use non-amd plugins without modify it
Here is lib edited to work with magento 2 https://gist.github.com/mrtuvn/f65ae7d460ebf11c9d04fcb31a04e32c

  • OK but why do we need to write whole path in shim config even if we mapped panaAccordion module id for it? Why can't we just write panaAccordion instead of js/accordion/pana-accordion inside shim? Dec 31, 2018 at 9:11
  • OK but are we spposed to rewrite every external lib to be able to integrate in magento ? I'm asking because we had some scripts in CMS that needed to be integrated to code since they depended on JQuery
    – medmek
    Oct 8, 2019 at 11:51
  • No, you don't have to modify any single thing in libraries; you can use the path config attribute which works with all libraries, not just AMD-compatible ones -- devdocs.magento.com/guides/v2.4/javascript-dev-guide/javascript/…
    – bfontaine
    Feb 10, 2022 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.