Importing draw2d in react causes jquery reference error

744 Views Asked by At

As soon as I add import draw2d from "draw2d" to my imports I get ReferenceError: jQuery is not defined.

I tried installing and adding jquery but still get same error...

import React, {Component} from "react";
import jQuery from "jquery";
import draw2d from "draw2d";
1

There are 1 best solutions below

6
Zohaib Ijaz On BEST ANSWER

Create a file with any name, e.g. import-jquery.js

import-jquery.js

import jquery from "jquery";

window.$ = window.jQuery = jquery;

App.js

import "import-jquery";
import "jquery-ui-bundle"; // you also need this
import "jquery-ui-bundle/jquery-ui.css";
import draw2d from "draw2d";

EDIT:

And don't forget to...

npm install jquery
npm install jquery-ui-bundle