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,302
  • 32
  • 43
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
  • 15,278
  • 11
  • 75
  • 80