jQuery($) not available in module file

I am using webpack to bundle my code. This is snippet from my main.js file where I am loading jQuery

main.js

    var $ = global.jQuery = require('jquery)
    $('someSelctor').on('rest of the code.') // This is working fine
    var importFile = require('someExport.js')
    importFile.someFunction();

someExport.js

module.exports = {
   someFunction :function(){
    $('someSelector').on(' some other code') // Error here. $ is not a function
   }
}

I also tried by load jquery like require('jquery') in someExport.js. But that does not resolved the issue. As jquery is already loaded by main.js do I need to load it again.Also how can use jquery in someExport.js file

Thanks you

Answers 1

  • Require jQuery in someExport.js :

    var $ = require(jquery);
    module.exports = {
       someFunction :function(){
        $('someSelector').on(' some other code') // Error here. $ is not a function
       }
    }
    

Related Articles