0

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?

2 Answers2

6

You have to use:

var $ = require('jquery');

or

import $ from 'jquery';
haotang
  • 5,520
  • 35
  • 46
2

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;
Roman
  • 19,236
  • 15
  • 93
  • 97