I have run the following command line arguments:
npm install --save jquery
npm install --save jquery-slimscroll
Inside of my index.js file, the first three lines import these modules:
import $ from 'jquery';
window.jQuery = $;
import 'jquery-slimscroll';
But I receive the following error:
jquery.slimscroll.js:474 Uncaught ReferenceError: jQuery is not defined
Any suggestions?
import jquery from 'jquery';
window.$ = window.jQuery=jquery;
Alright, now when I do:
import jquery from 'jquery';
window.$ = window.jQuery = jquery;
import 'jquery-slimscroll';
I still get the same error message:
jquery.slimscroll.js:474 Uncaught ReferenceError: jQuery is not defined
require('jquery-slimscroll');
instead of
import 'jquery-slimscroll';
Wow that was it. I didn't realize there was a difference between import and require in this case. Thanks for your help.
Went through this debugging exercise before. Here was my observation of the babel transpired js:
requires
, along with other statements.imports
at the top, before other statements ( in this case window.$ = window.jQuery = jquery;
), which caused the issue.There are probably some intricate reasons of babel's behavior, but I should stop being an ultracrepidarian ;-)
Seems like the problem is that jquery-slimscroll
apparently doesn鈥檛 attempt to do require('jquery')
even though it鈥檚 on npm. 馃槩
There are probably some intricate reasons of babel's behavior, but I should stop being an ultracrepidarian ;-)
Yes, per ES6 spec imports always execute first.
Most helpful comment
require('jquery-slimscroll');
instead of
import 'jquery-slimscroll';