In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "jQuery error Uncaught ReferenceError: $is not defined how to solve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "jQuery error Uncaught ReferenceError: $is not defined how to solve" it!
Recently, when I was learning about the writing application of Electron framework, I accidentally found that JQuery was introduced in this way in html. It was clearly introduced, but the program always reported an error: Uncaught ReferenceError: $is not defined.
After consulting the data, it is found that not only JQuery can not be used, but also RequireJS, Meteor and AngularJS can not be used.
The reason is that Electron introduces Node.js in the runtime environment, and the require module of Node.js is enabled by default, and these frameworks enable module introduction when require exists in Window to support the commondJS standard. So there are some additional variables in DOM, such as module, exports, and require. This causes many libraries to not function properly because they also need to add variables of the same name to the runtime environment.
There are many solutions, and the official solutions are 1 or 2:
1. Disable Node.js: if you do not use Node.js, disable Node.js in the main process to solve the problem.
/ / in the main process
Var mainWindow=new BrowserWindow ({
WebPreferences: {
NodeIntegration: false
}
})
2. Rename variables: if you still need to use the API provided by Node.js and Electron, you need to rename these variables before introducing those libraries.
/ / rename the require provided by Electron
Window.nodeRequire=require
Delete window.require
Delete window.exports
Delete window.module
In this way, you can use nodeRequire to use the node module, and you can use jQUery again, but this method is not suitable for web projects and will not work properly in web.
3. Introduce require with Node.js: (sometimes do not have the suffix .js)
Window.$=window.jQuery=require ("")
4. Customize the $and jQuery variables
If (typeof module==='object') {window.jQuery=window.$=module.exports;}
5 、
If (typeof module==='object') {window.module=module;module=undefined;}
If (window.module) module=window.module
6. Remove the modules in the framework and introduce the judgment code: for JQuery
How to code in JQuery
! function (jQuery requires a window with a document b) {"object" = = typeof module&& "object" = = typeof module.exports?module.exports=a.document?b (a): function (a) {if (! a.document) throw new Error ("jQuery requires a window with a document"); return b (a)}: B (a)}
Change to
! function (a) b) {b (a)}
Personally, I prefer to use the third, with less simple code.
Thank you for your reading, the above is the content of "jQuery error Uncaught ReferenceError: $is not defined how to solve". After the study of this article, I believe you have a deeper understanding of jQuery error Uncaught ReferenceError: $is not defined how to solve this problem, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.