简体   繁体   English

Webpack - 找不到模块:错误:无法解析“node_modules\\chokidar\\lib”

[英]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.

相关问题 找不到模块:错误:无法解析“/node_modules/html-webpack-plugin/lib/loader.js” - Module not found: Error: Can't resolve '/node_modules/html-webpack-plugin/lib/loader.js' 找不到模块:错误:无法解析“/node_modules/dotenv/lib”中的“fs”-创建反应应用程序 - Module not found: Error: Can't resolve 'fs' in '/node_modules/dotenv/lib' - create react app 找不到./node_modules/elasticsearch/src/lib/utils.js模块中的错误:错误:无法解析\\ node_modules \\ elasticsearch \\ src \\ lib&#39;中的“路径” - ERROR in ./node_modules/elasticsearch/src/lib/utils.js Module not found: Error: Can't resolve 'path' in \node_modules\elasticsearch\src\lib' 找不到模块:错误:无法解析&#39;/ workspace / node_modules / pace / node_modules / charm&#39;中的&#39;tty&#39; - Module not found: Error: Can't resolve 'tty' in '/workspace/node_modules/pace/node_modules/charm' Webpack resolve.fallback 不起作用。 未找到模块:错误:无法解析 node_modules\aws4 中的“加密” - Webpack resolve.fallback not working. Module not found: Error: Can't resolve 'crypto' in node_modules\aws4 找不到模块:无法在“C:\Users\name\ecom\node_modules\react-dom\lib”中解析“react/lib/React” - Module not found: Can't resolve 'react/lib/React' in 'C:\Users\name\ecom\node_modules\react-dom\lib' bcrypt, sequelize ERROR in ../node_modules/node-pre-gyp/lib/publish.js Module not found: Error: Can&#39;t resolve &#39;aws-sdk&#39; - bcrypt, sequelize ERROR in ../node_modules/node-pre-gyp/lib/publish.js Module not found: Error: Can't resolve 'aws-sdk' 错误 in./node_modules/fluent-ffmpeg/index.js 找不到模块:错误:无法解析 './lib-cov/fluent-ffmpeg' - ERROR in ./node_modules/fluent-ffmpeg/index.js Module not found: Error: Can't resolve './lib-cov/fluent-ffmpeg' Socket.io:找不到模块:无法解析'C \:... \ node_modules \ engine.io \ lib'中的'uws' - Socket.io: Module not found: Can't resolve 'uws' in 'C\:…\node_modules\engine.io\lib' 找不到模块:错误:无法解析“/home/user/Desktop/all/editor/node_modules/winston/dist/winston”中的“fs” - Module not found: Error: Can't resolve 'fs' in '/home/user/Desktop/all/editor/node_modules/winston/dist/winston'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM