我正在尝试使用Angular 8开发一个Electron 5应用程序。我已经在线学习了多个教程,但仍然遇到相同的错误。
我已经创建了一个新项目,运行了ng serve --open
,并且运行正常,我获得了默认的角度主页。
然后我用npm install --save-dev electron
安装了电子。我在项目的根目录中创建了main.js
文件,并放置了:
const { app, BrowserWindow } = require('electron')
let win;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('dist/myproject/index.html')
// Open the DevTools.
win.webContents.openDevTools()
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()
}
})
我也将<base href="/">
中的<base href="./">
更改为index.html
。
我也相应地修改了package.json
文件:
"main": "main.js",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "ng build && electron ."
},
运行npm run 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.
答案 0 :(得分:4)
在es5
和es2015
中都内置了角,Electron可能不喜欢这种犹豫不决。您的tsconfig.json
是否有适当的目标?
"target": "es5"