Uncaught ReferenceError: jQuery is not defined VueJS Parcel

偶尔善良 提交于 2021-01-28 08:32:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!