I'm trying to add a custom js file in magento 2 in the admin but all I can see are sample on how to add in the frontend. I found some that shows how to add in admin but none works. Below are my code that I copied from some sources

var config = {
    "map": {
        "*": {
            "generateMenu": "TCM_HeaderMenu/js/generateMenu"

and in the file located in app/code/COMPANY/PRODUCT/view/adminhtml/web/js/generateMenu.js

   * Copyright © Magento, Inc. All rights reserved.
   * See COPYING.txt for license details.

  ],  function($, logger) {
      'use strict';
      logger.log('inchoo.js is loaded!!');

      //creating jquery widget
      $.widget('generateMenu.js', {
          _create: function() {

              this.element.on('click', function(e){
                  logger.log("You click on element: " + e.target);


    return $.generateMenu.js;

But it seems that this is not being called when I refresh the page.

Note: I'm trying to load the custom js in Catalog->category page in the admin panel


Try :


var config = {

    deps: [



define(["jquery"], function($) {
  "use strict";
 //Your code here

clean cache

clean var/view_preprocessed content

clean pub/static content

deploy the static content : php bin/magento setup:static-content:deploy -f

| improve this answer | |
  • 1
    You're the star thanks a lot you saved me been looking for this answer for hours now – MadzQuestioning Aug 1 '19 at 13:11

please try with below code :

var config = {
    map: {
        '*': {

i hope its work for you

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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