gpt4 book ai didi

angularjs - Angular 应用程序在 Electron 中运行时会崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 23:32:48 27 4
gpt4 key购买 nike

我开始构建一个 Electron 应用程序,当我尝试在内部运行 Angular 分布时遇到一些问题。

对于 Angular 应用程序,我使用 yeoman 和 grunt 进行构建。如果我使用 gruntserve 开发 Angular 应用程序并在 localhost:9000 上运行它,则 Electron 应用程序可以很好地选择该应用程序。但是,如果我运行 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.

在 Electron 应用程序中,我使用express运行服务器,并且我还尝试选择通过express在localhost:8000运行 Angular 应用程序。那也没用。我还尝试运行另一个有 Angular 的应用程序,它部署在我的服务器上,并且在浏览器中工作正常 - 在 Electron 中不起作用。所有尝试都出现相同的错误。

我还必须提到,在所有情况下,如果我在浏览器中打开 Angular 应用程序,它就可以正常工作。

这是 Electron 代码:

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 初始化 Electron 的 BrowserWindow 修复了此问题

mainWindow = new BrowserWindow({width: 1024, height: 764, title: "app", webPreferences: {"nodeIntegration":false}});

关于angularjs - Angular 应用程序在 Electron 中运行时会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36189476/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com