节点webkit中的Require('jquery ui')产生navigator not found错

Require('jquery-ui') in node-webkit produces navigator not found error

本文关键字:navigator 产生 not found ui 中的 webkit 节点 jquery Require      更新时间:2023-09-26

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

core.js需要jqueryjquery-ui。当我启动应用程序时,我收到一个navigator is not defined错误。我试着在谷歌上搜索,但没有找到解决方案。有人知道是什么原因造成的吗?

这个问题与jquery ui无关。我可以用复制它

// index.html
<script>
require('./test.js');
</script>
// In test.js
console.log(navigator);

这是节点的require的限制,它只复制global的值,但navigator实际上不在global中。仅指定navigator在浏览器的上下文中有效,因为隐式全局变量不是由global提供的,而是由window对象提供的(请尝试window.x = 2; global.x = 3; console.log(x);)。

要解决这个问题,您可以简单地使用window中所需的变量初始化global,或者修复有问题的代码(即jQueryUI),以使用window.预先发送对navigator的引用。这应该适用于jQuery UI:

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