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">
        <script src="Demo_Barcodeinv::js/barcode_inv.js"/>      
        <referenceContainer name="content">
            <block class="Demo\Barcodeinv\Block\Adminhtml\Barcode" name="barcode" template="Demo_Barcodeinv::barcode.phtml"/>

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

<script type="text/x-magento-init">

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

], function ($) {
    'use strict';

    $.Barcodeinv = function()
       //some data
    $.Barcodeinv.prototype = {
        init: function (url)
    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.

  • Did u find a solution to this ? – Sarasranglt Jan 6 '19 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.