在Electron中运行时,有angular应用会中断
我开始构build一个Electron应用程序,当我尝试运行里面的angular度分布时,遇到了一些问题。
对于angular度的应用程序,我使用yeoman和咕噜build设。 如果我用grunt serve
开发angular度应用程序并在localhost:9000上运行,那么Electron应用程序可以很好地select应用程序。 但是,如果我运行grunt构build,并将Electron应用程序指向静态文件,则会出现一些angular度错误。
[$injector:modulerr] Failed to instantiate module clientApp due to: Error: [$injector:modulerr] Failed to instantiate module ngResource due to: Error: [$injector:nomod] Module 'ngResource' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
在电子应用程序运行一个服务器与快递,我也试图挑选运行angular应用程序通过express在localhost:8000。 那也行不通。 我也尝试运行另一个angular度的应用程序,它被部署在我的服务器上,并在浏览器中工作 – 在Electron中没有工作。 在所有的尝试相同的错误。
我还必须提到,在所有情况下,如果我在浏览器中打开angular度应用程序,它工作正常。
这是电子代码:
app.on('ready', function() { // Create the browser window. mainWindow = new BrowserWindow({width: 1024, height: 764, title: "uMaster"}); // and load the index.html of the app. var url = path.join(__dirname, "dist", "index.html"); url = "file://" + url; console.log(url); // mainWindow.loadURL(url); ---- this is not working in Electron // mainWindow.loadURL("http://localhost:8000"); -- not working when served by express mainwindow.loadURL("http://localhost:9000"); // working when angular runs with grunt serve // Emitted when the window is closed. mainWindow.on('closed', function() { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. mainWindow = null; }); /* ----------------------- */ });
通过使用nodeIntegration: false
初始化电子的BrowserWindow
解决这个问题nodeIntegration: false
mainWindow = new BrowserWindow({width: 1024, height: 764, title: "app", webPreferences: {"nodeIntegration":false}});
你的回答是正确的。 如果您想维护节点集成,您也可以在加载任何其他脚本之前在index.html
使用此代码:
<script> window.nodeRequire = require; delete window.require; delete window.exports; delete window.module; </script>
- 我怎样才能强制从浏览器窗口的外部链接打开在默认浏览器从电子?
- 如何用IntelliJ或WebStormdebugging电子应用程序?
- 电子 – 从菜单打开文件
- 如何在google appengine上为node.js运行nightmare.js
- 使用app.quit()closures电子应用程序中的所有打开的窗口是不好的做法?
- React和Electron with Bablify:Uncaught TypeError:fs.readFileSync不是一个函数
- 我怎样才能写文件到Windows系统文件夹?
- 最好的方式来读取一个大的CSV文件,而不使用Javascript加载到内存
- 在电子应用程序中使用libxml-xsd失败,并出现绑定错误