javascript - 如何修复: "Failed to load module script ..." Angular 8, Electron 5

标签 javascript angular electron

我正在尝试使用 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 在 es5es2015 中构建,Electron 可能不喜欢这种犹豫不决的情况。您的 tsconfig.json 是否有正确的目标:

"target": "es5"

关于javascript - 如何修复: "Failed to load module script ..." Angular 8, Electron 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57261456/

相关文章:

javascript - 仅使用 Electron (Atom shell) 和 PHP+mysql 服务器的身份验证表单

webpack - 无法创建中继容器; graphql.js 文件似乎有 webpack 工件?

javascript - 通过拖放将 KnockoutJS 与 JQuery 结合使用

javascript - 字符串编码器固定大小输出

javascript - NgRx @Effect 与 createEffect

angular - 如何将泛型类型参数传递给 Angular2 组件?

javascript - 如何从2个javascript数组中获取唯一记录?

javascript - 如何在浏览器控制台上使用纯 JavaScript 访问 GPT 数据?

javascript - 如何在 nw.js 中开始使用 angular2

javascript - 意外的 token 导入 - Electron/React