【发布时间】:2015-11-22 18:49:58
【问题描述】:
我正在使用Electron 制作桌面应用程序。在我的应用程序中,我正在加载一个外部站点(Atom 应用程序之外),比如说http://mydummysite/index.html 页面。
这是Atom Editor中我的应用程序的结构:
即它具有以下部分:
-
main.js package.json-
nodemodules>jquery(加载 jquery)
源代码:
main.js:
'use strict';
var app = require('app');
app.on('ready', function() {
var BrowserWindow = require('browser-window');
var win =
new BrowserWindow({ width: 800, height: 600, show: false,
'node-integration':true });
win.on('closed', function() {
win = null;
});
win.loadUrl('http://mydummysite/index.html ');
win.show();
});
package.json:
{
"name": "my-mac-app",
"version": "5.2.0",
"description": "My Mac Desktop App",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "Me",
"license": "ISC",
"dependencies": {
"jquery": "^2.1.4"
}
}
外部页面 - http://mydummysite/index.html 页面代码:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Hello World!</h1>
</body>
<script>
var jqr=require('jquery');
</script>
</html>
当我运行上述应用程序(通过将应用程序文件夹拖到 Electron)时,外部页面 (http://mydummysite/index.html) 在 Electron shell 中加载 但有错误
未捕获的错误:找不到模块“jquery”
你能帮我找出这个问题的原因吗?
正如您在我的目录结构屏幕截图中看到的,我已经将 jquery 模块安装到我的文件夹中,并且我通过 npm install jquery 命令完成了它。
注意:为了在 JS 中使用require 命令,我尝试在我的外部页面http://mydummysite/index.html 页面中添加require("ipc"),它正在工作,那么require("jquery") 可能是什么原因。
我是否在 Electron 中以正确的方式添加了外部模块(jquery)?
我是否缺少 package.json 中的某些依赖项?
我已经尝试过的:
-
npm cache clean,npm install jquery(到我的应用文件夹) npm install --save jquerynpm install jquery -gnpm rebuildsudo npm install jquery -gsudo npm install jqueryexport NODE_PATH=/usr/local/lib/node_modules
这是module.js中引发错误的位置的屏幕截图
有人能建议为什么require("ipc") 有效而require("jquery") 无效吗?
我的目标是将 jQuery 与具有节点集成的电子应用程序一起使用。
【问题讨论】:
-
github.com/UncoolAJ86/node-jquery/issues/35 不确定这个链接是否能解决,但它会让你开始。
-
Yan,您提到的情况是我们在 atom shell 应用程序中使用页面时的情况。我正在从外部 url 加载页面。
-
你能显示 jquery 包的 package.json 吗??
标签: javascript jquery node.js atom-editor electron