【发布时间】:2019-12-07 05:50:33
【问题描述】:
我正在尝试使用 Angular 8 制作一个 Electron 5 应用程序。我已经在线学习了几个教程,但仍然遇到同样的错误。
我已经创建了一个新项目,运行 ng serve --open 并且运行良好,我得到了默认的 Angular 主页。
然后我用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()
}
})
我还在index.html 中将<base href="/"> 更改为<base href="./">。
我也相应地修改了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.
【问题讨论】:
标签: javascript angular electron