【问题标题】:How to fix: "Failed to load module script ..." Angular 8, Electron 5如何修复:“无法加载模块脚本......”Angular 8,Electron 5
【发布时间】: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


    【解决方案1】:

    Angular 在 es5es2015 中构建,Electron 可能不喜欢优柔寡断。您的tsconfig.json 是否有正确的目标:

    "target": "es5"
    

    【讨论】:

    • 不,我会尝试这个解决方案,看看它是否能解决我的问题。谢谢你。编辑:它工作
    猜你喜欢
    • 2020-06-04
    • 2020-01-11
    • 2019-02-23
    • 2021-06-18
    • 1970-01-01
    • 2021-01-12
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多