Node-webkit中的Require('jquery-ui')会产生导航找不到错误 [英] Require('jquery-ui') in node-webkit produces navigator not found error

查看:213
本文介绍了Node-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 。当我启动应用程序时,我得到一个导航器未定义错误。我尝试谷歌搜索,但发现没有解决方案。有谁有任何想法是什么原因?

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 其中仅复制全局 ,但导航器实际上不在全局中。只需指定 navigator 在浏览器的上下文中工作,因为全局 >, window object(try window.x = 2; global.x = 3; console.log(x); )。

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 或修复有问题的代码(即jQuery UI),以使用窗口为导航器添加引用。。这应该适用于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');

这篇关于Node-webkit中的Require('jquery-ui')会产生导航找不到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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