我在用Electron https://github.com/atom/electron制作桌面应用程序。在我的应用程序中,我正在加载一个外部站点(Atom 应用程序之外)可以说http://mydummysite/index.html http://mydummysite/index.html page.
这是我的应用程序的结构原子编辑器 https://atom.io/:
即它具有以下部分:
-
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();
});
包.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 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 http://mydummysite/index.html) 在 Electron 壳中加载
但有错误
未捕获的错误:找不到模块“jquery”
你能帮我找出这个问题的原因吗?
正如您在目录结构的屏幕截图中看到的,我已经将 jquery 模块安装到我的文件夹中,并且通过以下方式完成npm install jquery
命令。
注意:一起玩require
我尝试添加 JS 中的命令require("ipc")
在我的外部页面中http://mydummysite/index.html http://mydummysite/index.html页面并且它正在工作,那么可能是什么原因require("jquery")
.
我是否在 Electron 中以正确的方式添加了外部模块(jquery)?
我是否缺少一些依赖package.json
?
我已经尝试过的:
-
npm cache clean
, npm install jquery
(到我的应用程序文件夹)
npm install --save jquery
npm install jquery -g
npm rebuild
sudo npm install jquery -g
sudo npm install jquery
export NODE_PATH=/usr/local/lib/node_modules
这是抛出错误的位置的屏幕截图module.js
有人可以建议为什么吗require("ipc")
正在工作并且require("jquery")
not?
我的目标是将 jQuery 与电子应用程序一起使用,并实现节点集成。