1

This question already has an answer here:

I've seen a few similar posts on the Magento SE but none seem to work for me. I'm probably missing something but I for whatever reason my JS is not being included. I have a theme

app/design/frontend/Vendor/default

Inside is the file tree:

|-composer.json
|-etc/
|-Magento_Catalog/
|-media/
|-registration.php
|-requirejs-config.js
|-theme.xml
|-web/

Inside my requirejs-config.js file is this:

var config = {
    map: {
        '*': {
            themejs: 'js/main'
        }
    }
};

and my web/js/main.js file:

define(['jquery'], function($)
{
    "use strict";

    return function themejs()
    {
        alert('hello world');
    }
});

I then run:

$ php bin/magento setup:static-content:deploy -f
$ php bin/magento cache:clean

I refresh my page but no alert is seen. I then do a find in the console tab and can't see my newly added .js file. What am I doing wrong?

marked as duplicate by Community Nov 20 '18 at 15:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Try this

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

        };


define([
  "jquery",
  "whatever lib you wanna use..."
], 
function($) {
  "use strict";

    $(document).ready(function($){
        console.log("DID IT! jQuery log complete.");
    });
    return;
});
  • why do I need owlcarousel? Or is this a suggested way of writing? – treyBake Nov 20 '18 at 12:07
  • yes, you can change as you want – Sourav Nov 20 '18 at 14:30
  • if it solve your problem please tick answer – Sourav Nov 20 '18 at 14:31
  • It does not I'm afraid :/ – treyBake Nov 20 '18 at 14:31
  • I edit so you can copy – Sourav Nov 20 '18 at 14:37

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