-1

When attempting to load my bundled script file in the browser I get:

Uncaught ReferenceError: jQuery is not defined

Which is supposedly coming from the the last line in my bundled underscore-min.js being the issue:

}()

Which doesn't make any sense? I'm not sure if something with the source map file is leading me astray. My configuration is such in webpack.config.js:

entry: {
  main: [ 
    './js/jquery.min.js', 
    './js/other.js', 
    './js/other2.js', 
    './js/underscore-min.js'
  ]
},     

...

plugins: {
  ...
  new webpack.ProvidePlugin({
    jquery: 'jquery',
    jQuery: 'jquery',
  }),
  ...
}

...

externals: {
  'jquery': 'jQuery',
  'jQuery': 'jQuery',
}

And without the above, heaps of other packages freak out which depend on jQuery. Is there something unique about the underscore-min.js script that is causing this?

2
  • 1
    is the jquery js file stored in the defined location? is it readible by the webserver? Commented Dec 19, 2018 at 8:18
  • Yes, it is readable by webpack. Before adding the ProvidePlugin declaration other files were complaining they couldn't access jQuery but now this is the only one that does. Commented Dec 19, 2018 at 16:08

1 Answer 1

-1

Just remove externals: { 'jquery': 'jQuery', 'jQuery': 'jQuery', }.

If you want to use externals,

entry: {
  main: [ 
    './js/jquery.min.js', 
    './js/other.js', 
    './js/other2.js', 
    './js/underscore-min.js'
  ]
},     

...

...

externals: {
  'jquery': {
     root:'jquery',
     commonjs2:'jquery',
     commonjs:'jquery',
     amd:'jquery'
   }
},
output:{
   ...
   libraryTarget:"umd"
}

And in your html,add the script tag <script src="some-resources/jquery.js"></script>

Sign up to request clarification or add additional context in comments.

1 Comment

If I remove this from externals, I receive other errors, cannot resolve jquery in xxx.js files.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.