0

First of all I'm still a newbie in web development. Okay, now to the question. I have these imports:

import $ from 'jquery'; 
window.jQuery = $;
window.$ = $;
global.jQuery = $;
import './assets/js/waves';

How do I properly import an external javascript to reactjs if my external javascript requires jquery?

Because based on what these guys have said:

reactjs, bootstrap and npm import - jQuery is not defined

Are ES6 module imports hoisted?

my imports will be hoisted, which results in my external "./assets/js/waves" js causing an error.

Uncaught ReferenceError: $ is not defined?

Thanks in advance!

7
  • How about this var $ = require('./lib/jquery.js'); window.jQuery = $; window.$ = $ Commented Jul 7, 2017 at 14:56
  • what about require(pathtojquery) ? Commented Jul 7, 2017 at 16:36
  • or import from 'pathtojquery' Commented Jul 7, 2017 at 16:36
  • Thanks @HemaNandagopal and ArslArsl. I tried those but still did not load. Even the jquery is not loading. What could I be doing wrong? Commented Jul 10, 2017 at 12:05
  • Do you have the jquery plugin cdn or check the whether the script is there in the path which you refered, Commented Jul 10, 2017 at 12:30

1 Answer 1

0
import * as jQuery from 'jquery';

Then you have a reference of jQuery and you may do with it what you like, for instance:

window.$ = jQuery;
Sign up to request clarification or add additional context in comments.

2 Comments

thanks @ideaboxer but somehow it still did not work. question, where do you think should I put this? In a component or in the parent (index)?
It must have something to do with the content of the waves.js file. Could you post (part of) its content so that we can analyze it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.