我正在尝试使用 Angular 8 制作一个 Electron 5 应用程序。我已经遵循了几个在线教程,但仍然遇到相同的错误。
我已经创建了一个新项目,运行 ng serve --open
它工作得很好,我得到了默认的 Angular 主页。
然后我用 npm install --save-dev electron
安装了 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.
最佳答案
Angular 在 es5
和 es2015
中构建,Electron 可能不喜欢这种犹豫不决的情况。您的 tsconfig.json 是否有正确的目标:
"target": "es5"
关于javascript - 如何修复: "Failed to load module script ..." Angular 8, Electron 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57261456/