在 Electron 的模板中(Typescript + Webpack),这个 Electron Forge ERROR 是什么?

10

我按照Electron Forge页面的介绍安装了Electron的模板。

npx create-electron-app my-new-app --template=typescript-webpack

然后,我运行

npm run start

my-new-app 文件夹内,命令行中弹出了以下错误信息:

$ npm run start

> my-new-app@1.0.0 start
> electron-forge start

✔ Checking your system
✔ Locating Application

An unhandled rejection has occurred inside Forge:
Error: Expected plugin to either be a plugin instance or a { name, config } object but found @electron-forge/plugin-webpack,[object Object]

Electron Forge was terminated. Location:
{}

我谷歌搜索了一下,但没有人遇到同样的错误。在一个星期之前,我可以使用上述模板而没有错误信息。因此,我复制了一个一周前创建的项目并运行它,成功了。然而,我运行了以下命令:

npm audit

有22个漏洞(3个中等,19个高危)。

错误如下:

got  <11.8.5 
Severity: moderate

and

minimatch  <3.0.5
Severity: high

使用npm audit fixnpm audit fix --force无法解决问题。因此,我通过重写package.jsonpackage-lock.json来修复此错误。然后删除node_modules文件夹并运行npm install

这些漏洞已经不存在了,但在运行npm run start之后,以上述问题再次出现。

我认为问题涉及@electron-forge/plugin-webpack。但是,我不知道如何解决它。

提前致谢。

3个回答

18

在 package.json 文件的 config.forge 选项下,插件字段按以下结构生成:

"plugins": [
  [
    "@electron-forge/plugin-webpack",
    {
      "mainConfig": "./webpack.main.config.js",
      "renderer": {
        "config": "./webpack.renderer.config.js",
        "entryPoints": [
          {
            "html": "./src/index.html",
            "js": "./src/renderer.ts",
            "name": "main_window",
            "preload": {
              "js": "./src/preload.ts"
            }
          }
        ]
      }
    }
  ]
]

将该结构更改为具有 nameconfig 字段的对象:

"plugins": [
  {
    "name": "@electron-forge/plugin-webpack",
    "config": {
      "mainConfig": "./webpack.main.config.js",
      "renderer": {
        "config": "./webpack.renderer.config.js",
        "entryPoints": [
          {
            "html": "./src/index.html",
            "js": "./src/renderer.ts",
            "name": "main_window",
            "preload": {
              "js": "./src/preload.ts"
            }
          }
        ]
      }
    }
  }
]

我似乎没有更新我的库,就出现了这个错误。提醒其他人注意。谢谢你的帮助。 - jboxxx

2

当您在本地运行插件时,修改插件语法只能解决问题。如果使用npm run make导出包,则只会显示一个白色空白屏幕。

如果遇到此类问题,请尝试此处的解决方案


感谢您的分享!我很感激! - suzuki

1

这是在 Electron Forge beta 73 或者该用户运行的任何版本中出现的问题 - 该 bug 已经被修复了


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接