javascript - jQuery 未定义,Electron

标签 javascript node.js reactjs electron adal

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

enter image description here

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, '/');    
};

身份验证上下文文件
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);

该应用程序卡在“我们注销您时稍等片刻”。

最佳答案

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

常用的解决方法如下。

  • 如果你加载像 <script src="http://code.jquery.com/jquery-1.11.1.js"></script> 这样的 jQuery 库, 请使用 <script>window.$ = window.jQuery = require('jquery')</script>当您通过 npm install --save jquery 安装 jQuery 时,而不是在 Electron 中.
  • 更改 nodeIntegration: truenodeIntegration: falseBrowserWindow 中禁用 Node.js实例。
  • !function(a,b){b(a)}替换jquery开头的内容作为Election中的静态资源 Assets .
    // 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)}
    
  • 关于javascript - jQuery 未定义,Electron,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59634908/

    相关文章:

    javascript - node.js 的打包/解包函数

    node.js - 如何子类化 Model 并正确添加静态方法?

    javascript - 如何使数组在 React Component 的表格中垂直输出?

    reactjs - 如何为生产 react 应用程序设置代理?

    javascript - 动画持续时间在 Safari 中表现不正常

    javascript - iframe 完成加载后加载指示器保留在 Firefox 中

    javascript - 使用 Javascript 将动画 GIF 分享到 Facebook

    javascript - JS通过构造器调用函数为对象添加属性

    node.js - 我可以先处理字段然后处理 Nodejs busboy 中的文件吗

    javascript - 将 json 对象返回给渲染方法 - React.js