node-webkit 中的 Require('jquery-ui') 会产生导航器未找到错误

2024-03-18

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

This core.js两者都需要jquery and jquery-ui。当我启动应用程序时,我得到一个navigator is not defined错误。我尝试用谷歌搜索但没有找到解决方案。有谁知道是什么原因造成的?


这个问题与jquery-ui无关。我可以用它来重现它

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

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

这是节点的限制require, which 仅复制以下值global https://github.com/joyent/node/blob/a5778cdf01425ae39cea80b62f9ec6740aec724a/lib/module.js#L415,但导航器实际上并不在global。只是指定navigator在浏览器上下文中工作,因为隐式全局变量是not由提供global,但是window对象(尝试window.x = 2; global.x = 3; console.log(x);).

要解决这个问题,您可以简单地使用所需的变量初始化全局window,或修复有问题的代码(即 jQuery UI)以在对导航器的引用前面添加window.。这应该适用于 jQuery UI:

global.document = window.document;
global.navigator = window.navigator;
require('jquery-ui');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

node-webkit 中的 Require('jquery-ui') 会产生导航器未找到错误 的相关文章