无法读取未定义的属性“createSnapshot”

The*_*Pot 5 node.js webpack electron electron-forge

由于我使用了Electron forge webpack 插件,所以当我执行时npm start,它会在编译预加载脚本步骤之后导致错误。它说错误在 Forge 内部
我检查了一下,这是文件观察器 api 中的错误,mainCompilation.fileSystemInfo未定义,因此它无法读取 prop createSnapShot 函数。

我应该怎么做才能解决此错误并启动我的应用程序?

日志:

> datapack-planet@0.0.0 start D:\program\datapack-planet
> electron-forge start

? Checking your system
? Locating Application
You have set packagerConfig.ignore, the Electron Forge webpack plugin normally sets this automatically.

Your packaged app may be larger than expected if you dont ignore everything other than the '.webpack' folder
? Preparing native dependencies
? Compiling Main Process Code
? Launch Dev Servers
? Compiling Preload Scripts

An unhandled rejection has occurred inside Forge:
TypeError: Cannot read property 'createSnapshot' of undefined
    at D:\program\datapack-planet\node_modules\html-webpack-plugin\lib\webpack5\file-watcher-api.js:13:36
    at new Promise (<anonymous>)
    at Object.createSnapshot (D:\program\datapack-planet\node_modules\html-webpack-plugin\lib\webpack5\file-watcher-api.js:12:10)
    at D:\program\datapack-planet\node_modules\html-webpack-plugin\lib\cached-child-compiler.js:219:35
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Electron Forge was terminated. Location:
{}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! datapack-planet@0.0.0 start: `electron-forge start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the datapack-planet@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dell\AppData\Roaming\npm-cache\_logs\2021-01-22T04_33_47_591Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我的package.json(不是全部,只有重要数据):

> datapack-planet@0.0.0 start D:\program\datapack-planet
> electron-forge start

? Checking your system
? Locating Application
You have set packagerConfig.ignore, the Electron Forge webpack plugin normally sets this automatically.

Your packaged app may be larger than expected if you dont ignore everything other than the '.webpack' folder
? Preparing native dependencies
? Compiling Main Process Code
? Launch Dev Servers
? Compiling Preload Scripts

An unhandled rejection has occurred inside Forge:
TypeError: Cannot read property 'createSnapshot' of undefined
    at D:\program\datapack-planet\node_modules\html-webpack-plugin\lib\webpack5\file-watcher-api.js:13:36
    at new Promise (<anonymous>)
    at Object.createSnapshot (D:\program\datapack-planet\node_modules\html-webpack-plugin\lib\webpack5\file-watcher-api.js:12:10)
    at D:\program\datapack-planet\node_modules\html-webpack-plugin\lib\cached-child-compiler.js:219:35
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Electron Forge was terminated. Location:
{}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! datapack-planet@0.0.0 start: `electron-forge start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the datapack-planet@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dell\AppData\Roaming\npm-cache\_logs\2021-01-22T04_33_47_591Z-debug.log
Run Code Online (Sandbox Code Playgroud)

解决:我重新启动项目。也许我错过了一些依赖项。我是从模板复制的,所以应该会按预期发生错误。

Sim*_*n H 10

我的解决方法是删除node_modulesand package-lock.json,然后运行

npm install --legacy-peer-deps
Run Code Online (Sandbox Code Playgroud)

非常现代的 npm 版本存在问题,这为您提供了似乎有效的旧版安装规则


小智 7

我遇到了同样的问题,在检查并更正安装的版本后解决了。

  • 运行npm ls webpack以显示缺少对等依赖项。这将帮助您确定应用程序所需的正确版本。

  • 更改为所需版本,保存package.json文件。

  • 删除两者package-lock.jsonnode_modules文件夹。

  • 跑步npm install

再次运行脚本。

  • 我通过“npx create-electron-app electro --template=webpack”进行全新安装,这些说明并没有解决问题 (3认同)