Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack - Uncaught ReferenceError: $ is not defined jquery

Tags:

jquery

webpack

I'm using webpack bundler for compiling react js code. However, I'm facing issue while working with third party libraries like jquery and velocity js.

I've imported jquery in custom js file at the top however, i'm still getting error.

/* Import libraries stylesheet */
import '../shared/lib/normalize.css';
import '../shared/lib/grid.css';
import '../shared/lib/tiny-scrollbar/tinyscrollbar.css';

/* Import main stylesheet */
import './main.scss';

/* Import libraries script */
import '../shared/lib/jquery-1.12.3.min.js';
import '../shared/lib/tiny-scrollbar/jquery.tinyscrollbar.min.js';
import '../shared/lib/velocity.min.js';
import '../components/card/cards.js';

/* Import main component */
import './main.jsx';
like image 991
Rahul Dagli Avatar asked Apr 07 '16 09:04

Rahul Dagli


People also ask

How do I fix uncaught Referenceerror is not defined in jQuery?

To solve this error, we simply add the jQuery CDN link or downloaded jQuery path link inside the head section. Example: This example resolves the error by adding the required CDN link inside the <script> tag.

Is not defined Webpack jQuery?

"jQuery is not defined" or "$ is not defined"This error happens when your code (or some library that you are using) expects $ or jQuery to be a global variable. But, when you use Webpack and require('jquery') , no global variables are set.


1 Answers

Added jquery plugin in webpack solved the issue.

 plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery"
        })
    ]
like image 109
Rahul Dagli Avatar answered Oct 16 '22 08:10

Rahul Dagli