【问题标题】:jQuery is not defined, ElectronjQuery 未定义,Electron
【发布时间】:2020-01-08 16:17:20
【问题描述】:

我在我的电子应用程序中使用 microsoft adal 进行身份验证。在我的应用程序中没有使用 jQuery,但是当我尝试注销时,[我在我的应用程序控制台中收到此错误]

const redirectTo = `https://login.microsoftonline.com/${config.Adal.TenantID}/oauth2/v2.0/logout?post_logout_redirect_uri=${authContext.config.postLogoutRedirectUri}`;

const logout = () => {
    authContext.logOut();
    redirect(redirectTo, '/');    
};

authContext 文件

export const adalConfig = {
  clientId: config.Adal.ClientID,
  tenant: config.Adal.TenantID,
  cacheLocation: 'localStorage',
  redirectUri: config.Adal.RedirectURI,
  postLogoutRedirectUri: loginUrl
};

export const authContext = new AuthenticationContext(adalConfig);

应用卡在“请稍等,我们将您退出”。

【问题讨论】:

  • 您找到解决方案了吗?在将 Microsoft 身份提供程序与 Electron 一起使用时,我遇到了完全相同的问题。该应用程序卡在“我们退出时请稍等。”
  • 很遗憾没有,我不得不分叉 msal 库,然后对身份验证的工作方式进行一些更改。

标签: javascript node.js reactjs electron adal


【解决方案1】:

如果您尝试在关键字Uncaught ReferenceError: jQuery is not definedElectron 中搜索您的问题,您将获得许多解决方案。

常用的解决方案如下。

  1. 如果你加载像<script src="http://code.jquery.com/jquery-1.11.1.js"></script>这样的jQuery库,当你通过npm install --save jquery安装jQuery时,请在Electron中使用<script>window.$ = window.jQuery = require('jquery')</script>而不是它。

  2. nodeIntegration: true 更改为 nodeIntegration: false 以禁用 BrowserWindow 实例中的 Node.js。

  3. 将下面jQuery的开头内容替换为!function(a,b){b(a)}的Election中的静态资源资产。

    // The beginning content need to be replaced
    !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}
    

【讨论】:

  • 就像我说的,我没有在我的应用程序的任何地方使用 jQuery,那么为什么会出现这个错误?在浏览器中运行时也不会发生此错误。
  • 显然您项目的依赖项之一确实使用了 jquery。
猜你喜欢
  • 2015-12-13
  • 2017-11-11
  • 2017-07-22
  • 2016-03-17
  • 2021-08-01
  • 2020-07-23
  • 1970-01-01
  • 2020-03-08
相关资源
最近更新 更多