The problem
Today I’ve had the problem that I’ve tried to include JQuery in my project, where I use Webpack. First, I tried the tutorial from the official Webpack documentation, but I still got the error $ is not a function .
The solution
First, you install JQuery with the node package manager:
npm i jquery
Next define the variable Webpack in your webpack webpack.conf file:
var webpack = require("webpack");
Then you can set the jQuery variables in your plugins configuration:
plugins: [
new webpack.ProvidePlugin({
$: require.resolve('jquery'),
jQuery: require.resolve('jquery')
}),
],