节点Webkit中的Require(' jquery-ui')产生导航器未找到错误 [英] Require('jquery-ui') in node-webkit produces navigator not found error

查看:71
本文介绍了节点Webkit中的Require(' jquery-ui')产生导航器未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过npm为我的node-webkit项目安装了 jquery jquery-ui .我还有一个 index.html ,它在启动时由node-webkit加载,并加载 core.js .

I have installed jquery and jquery-ui via npm for my node-webkit project. I also have a index.html which is loaded by node-webkit at startup and which loads a core.js.

core.js 同时需要 jquery jquery-ui .启动应用程序时,出现未定义 navigator 的错误.我尝试使用Google搜索,但没有找到解决方案.有谁知道这是什么原因?

This core.js requires both jquery and jquery-ui. When I start the app I get a navigator is not defined error. I tried googling it but found no solution. Has anyone an idea what causes this?

推荐答案

此问题与jquery-ui无关.我可以用

This problem is unrelated to jquery-ui. I can reproduce it with

// index.html
<script>
require('./test.js');
</script>

// In test.js
console.log(navigator);

这是节点 require 的限制,

This is a limitation of node's require, which only copies over the values of global, but navigator is not actually in global. Just specifying navigator works in the browser's context since the implicit globals are not provided by the global, but the window object (try window.x = 2; global.x = 3; console.log(x);).

要解决此问题,您可以简单地使用 window 中所需的变量来初始化global,或者修复有问题的代码(即jQuery UI)以使用 window预先添加对导航器的引用..这应该适用于jQuery UI:

To fix this problem, you can simply initialize global with the required variables from window, or fix the code in question (i.e. jQuery UI) to prepend references to navigator with window.. This should do for jQuery UI:

global.document = window.document;
global.navigator = window.navigator;
require('jquery-ui');

这篇关于节点Webkit中的Require(&amp;#39; jquery-ui&amp;#39;)产生导航器未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆