3

I'm trying to use a JQuery Plugin (SignalR) inside my React application.

What I did is :

  1. Install jquery via npm ;
  2. Install the signalr client via npm ;
  3. Add entries in webpack.config to specify jQuery and SignalR paths ;
  4. Use import $ from 'jquery' and import 'msSignalrClient' in the React component I want to.

But that doesn't seem to work as I get this error : jquery.signalR.min.js?dc9f:9Uncaught Error: jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.

One workaround that works is to load in jQuery like this inside my index.html : <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>. Of course it's not optimal at all, and I'd like to import jQuery with the method I explained above. Any help appreciated !

2

2 Answers 2

3

this should work:

npm install jquery signalr expose-loader --save

//inside vendor.ts
import 'expose-loader?jQuery!jquery';
import '../node_modules/signalr/jquery.signalR.js';
Sign up to request clarification or add additional context in comments.

Comments

1

What I did in the end is this:

window.$ = window.jQuery = require("jquery");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.