gpt4 book ai didi

angular - 全新 Angular 8/Electron 5 应用出现白屏

转载 作者:太空狗 更新时间:2023-10-29 17:11:52 29 4
gpt4 key购买 nike

我正在构建和运行 Angular 8/Electron 5 桌面应用程序。在我认为正确设置后,运行该应用程序会显示空白屏幕。

使用:
Electron 5.0.2
Angular CLI 8.0.1
节点 10.16.0
macOS Mojave 10.14.5
...

ng new my-app
npm i -D electron

package.json

{
...
"main": "main.js", //<-- ADDED
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "ng build --baseHref=./ && electron ." //<-- ADDED
}
...
}

ma​​in.js

const { app, BrowserWindow } = require("electron");
const path = require("path");
const url = require("url");

let win;

function createWindow() {
win = new BrowserWindow({ width: 800, height: 600 });

win.loadURL(
url.format({
pathname: path.join(__dirname, `/dist/index.html`), //<-- CHANGED
protocol: "file:",
slashes: true
})
);

win.on("closed", () => {
win = null;
});
}

app.on("ready", createWindow);

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});

app.on("activate", () => {
if (win === null) {
createWindow();
}
});

我还将 angular.json 中的 outputPath 更改为“dist”

  {
...
"outputPath": "dist"
...
}

使用 npm run electron 启动应用程序

当应用程序打开时,我看到一个空白的白色屏幕。检查后,我可以看到 body 和 <app-root>元素,但我在页面上看到的只是一个空白的白色屏幕。

在做 ng new my-app 时我在 CLI 中尝试了使用和不使用路由启用标志。

在 Electron 安全警告之前,在 Electron 应用程序控制台中获取这些错误:

runtime-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
styles-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
main-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
polyfills-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
vendor-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.

最佳答案

我通过将 tsconfig.json 中的 target 更改为 es5 让我的 Electron 应用程序工作。

{
"compileOnSave": false,
"compilerOptions": {
"importHelpers": true,
"module": "esnext",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5", <-- HERE
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}

在此之前,我在更新 Angular 8 后也出现了空白(白色)屏幕。现在看来 Angular 在 es5es2015 中都进行了构建, Electron 不喜欢那样。我想这会在未来得到解决。

2019-10-24 更新:

看起来这是在 electron@7.0.0 中修复的。您可以使用该版本定位 es2015。使用 @angular/cli@8.3.14 进行测试。

关于angular - 全新 Angular 8/Electron 5 应用出现白屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56400290/

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