当我使用 npm 包“Electron-reload”编译我的 Electron 应用程序时。我有一个错误。显然,Electron-reload 使用 chokidar 来监视我的应用程序文件,因此它可以在检测到文件更改时重新加载它。
使用 webpack 编译电子主进程时出现的错误:
WARNING in ./node_modules/chokidar/lib/fsevents-handler.js
Module not found: Error: Can't resolve 'fsevents' in
'C:\[...]\node_modules\chokidar\lib'
我的电子应用程序运行时出现的错误:
TypeError: Cannot read property 'filename' of undefined
at Object.eval (webpack:///./node_modules/electron-reload/main.js?:12:32)
at eval (webpack:///./node_modules/electron-reload/main.js?:86:30)
at Object../node_modules/electron-reload/main.js (C:\[...]\Dist\Electron\app.js:322:1)
at __webpack_require__ (C:\[...]\Dist\Electron\app.js:20:30)
at eval (webpack:///./Electron/app.ts?:5:5)
at Object../Electron/app.ts (C:\[...]\Dist\Electron\app.js:109:1)
at __webpack_require__ (C:[...]\Dist\Electron\app.js:20:30)
at C:\[...]\Dist\Electron\app.js:84:18
at Object.<anonymous> (C:\[...]\Dist\Electron\app.js:87:10)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
我无法从 Electron-reload、chokidar 或 webpack 在线找到任何有用的东西。这是我的 webpack.config.js
const path = require('path');
module.exports = {
mode: "development",
entry: "./Electron/app.ts",
target: "electron-main",
module: "es6",
watch: true,
stats: 'minimal',
output: {
path: path.resolve(__dirname, "./Dist/Electron/"),
filename: "app.js",
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
include: /Electron/,
},
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
}
}
感谢您的帮助。