cancel
Showing results for 
Search instead for 
Did you mean: 

Require Js Error: Mismatched anonymous define() module: function Magento 2

Require Js Error: Mismatched anonymous define() module: function Magento 2

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.

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.