4

I am facing Error: Mismatched anonymous define() module: function ($) { 'use strict'; require.js on line 166 error in my custom extension when i am trying to load external js.

Below is my code. Let me know if i am doing anything wrong. app/code/Demo/Barcodeinv/view/adminhtml/layout/barcodeinv_barcode_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script src="Demo_Barcodeinv::js/barcode_inv.js"/>      
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Demo\Barcodeinv\Block\Adminhtml\Barcode" name="barcode" template="Demo_Barcodeinv::barcode.phtml"/>
        </referenceContainer>
    </body>
</page>

Here is the code for app/code/Demo/Barcodeinv/view/adminhtml/templates/barcode.phtml

<script type="text/x-magento-init">
require(['jquery','inventory_code'],function(inventory_code){
        inventory_code.init('url');
});
</script>

I have put the js file at app/code/Demo/Barcodeinv/view/adminhtml/web/js/barcode_inv.js

define([
    "jquery",
    "jquery/ui",
    "domReady!"
], function ($) {
    'use strict';

    $.Barcodeinv = function()
    {
       //some data
    };
    $.Barcodeinv.prototype = {
        init: function (url)
        {
            //somedata
        }
    }
    return new $.Barcodeinv();
});// JavaScript Document

and path for requirejsconfig is app/code/Demo/Barcodeinv/view/adminhtml/requirejs-config.js

var config = {
    map: {
        '*': {
            inventory_code: 'Demo_Barcodeinv/js/barcode_inv'
        }
    }
};

Thanks in advance for yur help.

2
  • Did u find a solution to this ? Jan 6, 2019 at 13:49
  • Anyone got a solution for that ?
    – Claims
    Oct 8, 2022 at 20:58

0

Your Answer

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

Browse other questions tagged or ask your own question.