[英]Webpack - Module not found: Error: Can't resolve 'node_modules\chokidar\lib'
When I compile my Electron application with the npm package "Electron-reload".当我使用 npm 包“Electron-reload”编译我的 Electron 应用程序时。 I got an error.
我有一个错误。 Apprently, Electron-reload use chokidar to watch my applications files, so It can reload it when a file change is detected.
显然,Electron-reload 使用 chokidar 来监视我的应用程序文件,因此它可以在检测到文件更改时重新加载它。
The error I have when compiling my electron main process with webpack :使用 webpack 编译我的电子主进程时出现的错误:
WARNING in ./node_modules/chokidar/lib/fsevents-handler.js
Module not found: Error: Can't resolve 'fsevents' in
'C:\[...]\node_modules\chokidar\lib'
And the error I have when my electron application is running :我的电子应用程序运行时出现的错误:
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)
I can't find anything useful online from Electron-reload, chokidar or webpack.我在 Electron-reload、chokidar 或 webpack 上找不到任何有用的在线信息。 Here is my webpack.config.js
这是我的 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']
}
}
thank you for your help.感谢您的帮助。
Okay, I didn't resolved the original problem.好吧,我没有解决原来的问题。 But since I only wanted to reload my electron render process when a file is changed, I found another way of doing it without "Electron-Reload"
但是因为我只想在文件更改时重新加载我的电子渲染过程,所以我找到了另一种没有“电子重新加载”的方法
Inside the function that render my main window I added :在渲染我的主窗口的函数中,我添加了:
import {join} from 'path';
import {watch} from 'fs';
app.whenReady().then(()=>{
watch('./Dist/Client/', (eventType, filename)=>{ win.reload(); })
}
Everything is working fine now.现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.