Search code examples
node.jsreactjsdraw2d-js

Importing draw2d in react causes jquery reference error


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";

Solution

  • 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