无法读取未定义的 属性 'createSnapshot'
Cannot read property 'createSnapshot' of undefined
由于我使用了Electron forge webpack插件,所以在执行npm start
的时候会报错Compiling Preload Scripts[=33] =].它说错误是 inside 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\_logs21-01-22T04_33_47_591Z-debug.log
我的package.json
(不是全部,只有重要数据):
{
"main": "./.webpack/main",
"devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.54",
"@electron-forge/maker-deb": "^6.0.0-beta.54",
"@electron-forge/maker-rpm": "^6.0.0-beta.54",
"@electron-forge/maker-squirrel": "^6.0.0-beta.54",
"@electron-forge/maker-zip": "^6.0.0-beta.54",
"@electron-forge/plugin-webpack": "^6.0.0-beta.54",
"@marshallofsound/webpack-asset-relocator-loader": "^0.5.0",
"@types/jquery": "^3.5.5",
"@types/node": "^14.14.22",
"electron": "^11.1.1",
"fork-ts-checker-webpack-plugin": "^6.1.0",
"html-loader": "^1.3.2",
"jquery": "^3.5.1",
"less": "^4.1.0",
"less-loader": "^7.2.1",
"node-loader": "^1.0.2",
"ts-loader": "^8.0.14",
"typescript": "^4.1.3",
"webpack": "^5.16.0",
"webpack-cli": "^4.4.0"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"jquery": "^3.5.1"
},
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"config": {
"forge": {
"packagerConfig": {
"ignore": [
"\.(idea|git)",
"config\.json",
"[A-Z]",
"md$"
]
},
"makers": [
// There is some auto-generated settings, I didn't changed it.
// So I skip those configs.
],
"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"
}
]
}
}
]
]
}
}
}
解决: 我重启项目。也许我错过了一些依赖关系。我是从模板中复制过来的,所以bug应该是按预期出现的。
运行 npm install
或 yarn
在项目中,安装项目的依赖项
我遇到了同样的问题,在检查并更正安装的版本后已解决。
运行 npm ls webpack
以显示缺少对等依赖项。这将帮助您找出您的应用所需的正确版本。
更改为所需版本,保存 package.json 文件。
同时删除 package-lock.json
和 node_modules
文件夹。
运行 npm install
.
运行 再次脚本。
我遇到了同样的问题,它似乎是 compatibility issue with npm7 and plugin-webpack。
有几个解决方案,但对我来说最简单的是简单地使用 yarn
而不是 npm
。
- 删除
node_modules/
- 删除
package-lock.json
- 运行
yarn install
- 运行
yarn start
这对我有用,如果有帮助请告诉我!
我的解决方法是删除 node_modules
和 package-lock.json
,然后删除 运行
npm install --legacy-peer-deps
非常现代的 npm 版本存在问题,这为您提供了似乎有效的旧版安装规则
这是由于您的 webpack 版本不匹配,只需检查 npm list webpack,您将能够看到类似未满足的内容 dependecies.Just 创建 peerDependencies 并将 webpack 添加到其中或者可以删除 webpack inteself.Check你的 ts-loader 版本也是,它应该小于 9.see the magic :)
由于我使用了Electron forge webpack插件,所以在执行npm start
的时候会报错Compiling Preload Scripts[=33] =].它说错误是 inside 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\_logs21-01-22T04_33_47_591Z-debug.log
我的package.json
(不是全部,只有重要数据):
{
"main": "./.webpack/main",
"devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.54",
"@electron-forge/maker-deb": "^6.0.0-beta.54",
"@electron-forge/maker-rpm": "^6.0.0-beta.54",
"@electron-forge/maker-squirrel": "^6.0.0-beta.54",
"@electron-forge/maker-zip": "^6.0.0-beta.54",
"@electron-forge/plugin-webpack": "^6.0.0-beta.54",
"@marshallofsound/webpack-asset-relocator-loader": "^0.5.0",
"@types/jquery": "^3.5.5",
"@types/node": "^14.14.22",
"electron": "^11.1.1",
"fork-ts-checker-webpack-plugin": "^6.1.0",
"html-loader": "^1.3.2",
"jquery": "^3.5.1",
"less": "^4.1.0",
"less-loader": "^7.2.1",
"node-loader": "^1.0.2",
"ts-loader": "^8.0.14",
"typescript": "^4.1.3",
"webpack": "^5.16.0",
"webpack-cli": "^4.4.0"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"jquery": "^3.5.1"
},
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"config": {
"forge": {
"packagerConfig": {
"ignore": [
"\.(idea|git)",
"config\.json",
"[A-Z]",
"md$"
]
},
"makers": [
// There is some auto-generated settings, I didn't changed it.
// So I skip those configs.
],
"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"
}
]
}
}
]
]
}
}
}
解决: 我重启项目。也许我错过了一些依赖关系。我是从模板中复制过来的,所以bug应该是按预期出现的。
运行 npm install
或 yarn
在项目中,安装项目的依赖项
我遇到了同样的问题,在检查并更正安装的版本后已解决。
运行
npm ls webpack
以显示缺少对等依赖项。这将帮助您找出您的应用所需的正确版本。更改为所需版本,保存 package.json 文件。
同时删除
package-lock.json
和node_modules
文件夹。运行
npm install
.
运行 再次脚本。
我遇到了同样的问题,它似乎是 compatibility issue with npm7 and plugin-webpack。
有几个解决方案,但对我来说最简单的是简单地使用 yarn
而不是 npm
。
- 删除
node_modules/
- 删除
package-lock.json
- 运行
yarn install
- 运行
yarn start
这对我有用,如果有帮助请告诉我!
我的解决方法是删除 node_modules
和 package-lock.json
,然后删除 运行
npm install --legacy-peer-deps
非常现代的 npm 版本存在问题,这为您提供了似乎有效的旧版安装规则
这是由于您的 webpack 版本不匹配,只需检查 npm list webpack,您将能够看到类似未满足的内容 dependecies.Just 创建 peerDependencies 并将 webpack 添加到其中或者可以删除 webpack inteself.Check你的 ts-loader 版本也是,它应该小于 9.see the magic :)