问题
I have this:
import jQuery from 'jquery'
import HSCore from './components/assets/js/hs.core.js'
Yet I still get this:
Uncaught ReferenceError: jQuery is not defined
at Object.parcelRequire.client/components/assets/js/hs.core.js (hs.core.js:177)
Why 😑
import jQuery from 'jquery'
does actually import jQuery (via console.log(jQuery)
), but my other JS file is having problems accessing it(?). This is in a Vue file using Parcel loader.
hs.core.js file:
(function ($) {
...
})(jQuery); //<-- line 177
回答1:
This will do it:
const { $, jQuery } = require('jquery');
global.$ = $;
global.jQuery = jQuery;
require( './components/assets/js/hs.core.js');//<-- this made it work with all the above code too
// $ object now exists: $(“#el”)
// jQuery now exists: jQuery(“#el”)
来源:https://stackoverflow.com/questions/54962921/uncaught-referenceerror-jquery-is-not-defined-vuejs-parcel