1

I have done everything mentioned in this post, however, it gives me an error in console:

require.js:166 Uncaught Error: Mismatched anonymous define() module: function ($, getTotalsAction, customerData) {

$(document).ready(function(){
$(document).on('change', 'input[name$="[qty]"]', function(){
    var form = $('form#form-validate');
    $.ajax({
        url: form.attr('action'),
        data: form.serialize(),
        showLoader: true,
        success: function (res) {
            var parsedResponse = $.parseHTML(res);
            var result = $(parsedResponse).find("#form-validate");
            var sections = ['cart'];

            $("#form-validate").replaceWith(result);

            // The mini cart reloading
            customerData.reload(sections, true);

            // The totals summary block reloading
            var deferred = $.Deferred();
            getTotalsAction([], deferred);
        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
   });
  });
}

No idea how to solve this...

UPDATE:

I am not using a custom module, all the code is being added to the custom theme directory.

4
  • Are you creating custom js for your module?
    – Ajithkumar
    Commented Dec 12, 2018 at 17:34
  • No, I am not. The reference material never mentioned a post. All the changes are made in the custom theme.
    – Greg
    Commented Dec 13, 2018 at 9:08
  • try require instead of define
    – Ajithkumar
    Commented Dec 13, 2018 at 9:12
  • If you take a look a the js.phtml file, there is a require already added above the whole js document.
    – Greg
    Commented Dec 13, 2018 at 9:18

1 Answer 1

3

You can follow steps given below to resolve the issue.

step 1) Please move the custom.js file

To

app/design/frontend/Vendor/customtheme/Magento_Theme/web/js

step 2) Update your requirejs-config.js as given below

var config = {
   map: {
    '*': {
        custom:'Magento_Theme/js/custom'
    }
  }
};

step 3) Please update js.phtml located under /app/design/frontend/Vendor/customtheme/Magento_Theme/templates/

File : js.phtml

<script>
require ([
        'jquery',
    ],
    function ($) {
       $(window).on("load", function () {
            require([
                'custom'
            ]);
        });
    });
</script>    

Please remove static content (sudo rm -rf pub/static/frontend/*) and flush cache

3
  • It actually worked... what is the reason why it didn't work the other way?
    – Greg
    Commented Dec 13, 2018 at 14:43
  • The reason is custom.js file location was not correct. that's why it was not working properly. Commented Dec 14, 2018 at 10:14
  • I did what you said but it didn't work for me Commented Dec 17, 2018 at 6:51

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.