Search code examples
jquerywebpackwebpack-2webpack-3

Webpack 3 'Uncaught ReferenceError: jquery is not defined'


I'm trying to add jQuery in the bundle, so far webpack 3 is not making it easy, i've seen the question asked several times, and none of the answers worked.

I added all the parts that are supposed to make this work

In webpack.config.js

  externals: {
    jquery: 'jQuery'
  },
  plugins: [
    new webpack.DefinePlugin({
      '$': 'jquery',
      'jQuery': 'jquery',
      'window.jQuery': 'jquery'
    })
  ]

In entry file: app.jsx

window.$ = window.jQuery = require("jquery");

Webpack compiles, but in the browser I get the same error enter image description here

Here's the repo, incase anyone wanna take a look at the files

Thanks alot in advance :)


Solution

  • You need to use ProvidePlugin, not DefinePlugin. And also remove "externals" section.