-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?

dalanmiller
  • 3,467
  • 5
  • 31
  • 38
  • 1
    is the jquery js file stored in the defined location? is it readible by the webserver? – Lelio Faieta Dec 19 '18 at 08: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. – dalanmiller Dec 19 '18 at 16:08

1 Answers1

-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>

lx1412
  • 1,160
  • 6
  • 14