Magento 2 – RequireJS Config Not Being Read

magento2requirejsrequirejs-config.js

I am trying to add slick.js to my website. I started by following this tutorial- http://inchoo.net/magento-2/magento-2-slick-carousel/

I have my slick.min.js here- >app/design/frontend/vendor/theme/web/js/slick.min.js.

I created a requirejs-config.js at app/design/frontend/vendor/theme/web/
(after looking at the comments on the tutorial it mentions to move the file to app/design/frontend/vendor/theme/, so I did all of these steps at both locations.)

I pasted this code in the new requirejs-config.js file-

var config = {
   paths: {
    slick:        'js/slick'
},
shim: {
    slick: {
        deps: ['jquery']
    }
  }
};

I cleaned and flushed the cache, and ran php bin/magento setup:static-content:deploy(I am in developer mode so I do not believe it does anything).

I started researching and came across this answer- Magento2 not reading my requirejs-config.js

I deleted the requirejs-config.js here- >pub/static/_requirejs/frontend/Namespace/Theme/en_US/requirejs-config.js

After that, I ran

 php bin/magento cache:clean
 php bin/magento cache:flush
 php bin/magento setup:upgrade
 php bin/magento setup:di:compile

Still can't get that code to show up in require.js. Please advise on what I can try next.

Best Answer

  1. The requirejs-config.js should be in : app/design/frontend/{Vendor}/{theme}/requirejs-config.js and not in app/design/frontend/{Vendor}/{theme}/web/requirejs-config.js

  2. Your requirejs-config.js should be like this:

    var config = {
        paths: {
            slick: 'js/slick.min'
        },
        shim: {
            slick: {
                deps: ['jquery']
            }
        }
    };
    
  3. Remove the content of :

    var/view_preprocessed, var/cache, var/page_cache

  4. compile the static contents : php bin/magento setup:static-content:deploy -f