user5965280
user5965280

Reputation:

Nodejs Uncaught ReferenceError: $ is not defined after var jQuery = require('jquery');

I installed jQuery and it is not my question:

npm install jquery

I try to include jQuery library into my page like this:

var jQuery = require('jquery'); or
import jQuery from "jquery";

and get in Chrome console:

Uncaught ReferenceError: $ is not defined

How can I overcome it?

Upvotes: 0

Views: 4589

Answers (2)

Roman
Roman

Reputation: 21785

In my cases the following works well:

global.jQuery   = require('jquery');
global.$        = global.jQuery;

or if you prefer "window" or it is obviously present, then:

typeof window !== "undefined" ? window : this;
window.jQuery   = require('jquery');
window.$        = window.jQuery;

Upvotes: 2

haotang
haotang

Reputation: 5708

You have to use:

var $ = require('jquery');

or

import $ from 'jquery';

Upvotes: 6

Related Questions