Electron: jQuery is not defined

前端 未结 19 2497
我在风中等你
我在风中等你 2020-11-22 06:20

Problem: while developing using Electron, when you try to use any JS plugin that requires jQuery, the plugin doesn\'t find jQuery, even if you load in the correct path using

19条回答
  •  醉酒成梦
    2020-11-22 06:53

    As seen in https://github.com/atom/electron/issues/254 the problem is caused because of this code:

    if ( typeof module === "object" && typeof module.exports === "object" ) {
      // set jQuery in `module`
    } else {
      // set jQuery in `window`
    }
    

    The jQuery code "sees" that its running in a CommonJS environment and ignores window.

    The solution is really easy, instead of loading jQuery through

    Note: the dot before the path is required, since it indicates that it's the current directory. Also, remember to load jQuery before loading any other plugin that depends on it.

提交回复
热议问题