Home > Blockchain >  How do I fix "jQuery is not defined" error?
How do I fix "jQuery is not defined" error?

Time:05-13

I am compiling my JavaScript code using Laravel Mix.

This is my JS code:

import $ from 'jquery';
window.$ = window.jQuery = $;

I have also tried:

import {$,jQuery} from 'jquery';
window.$ = $;
window.jQuery = jQuery;

This used to work earlier, but suddenly today, in my front end code, It is saying:

jQuery is not defined

jQuery version: 3.6.0

laravel-mix version: 6.0.6

Can anyone help me?

CodePudding user response:

In bootstrap.js...

window._ = require('lodash');
window.$ = window.jQuery = require('jquery');

CodePudding user response:

In your bootstrap.js define with try{}..catch{}

try {
    window.$ = window.jQuery = require('jquery');
} catch (e) {}
  • Related