Open hujun199103 opened 2 years ago
IS there any solution fo this ??
facing same problem
This is because the web base browser do not support fs package, but node have, so you can either set the target in webpack config to "node" or "electron" https://webpack.js.org/configuration/target/
configureWebpack: { target: 'electron' }
Version
5.0.8
Environment info
Steps to reproduce
终端运行:yarn electron:serve 出现如下错误 ERROR Failed to compile with 2 errors 16:45:23
error in ../node_modules/electron/index.js
Module not found: Error: Can't resolve 'fs' in 'E:\programing\electron\chapter1\node_modules\electron'
error in ../node_modules/electron/index.js
Module not found: Error: Can't resolve 'path' in 'E:\programing\electron\chapter1\node_modules\electron'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
ERROR in ../node_modules/electron/index.js 3:11-24 Module not found: Error: Can't resolve 'fs' in 'E:\programing\electron\chapter1\node_modules\electron' @ ../node_modules/@electron/remote/dist/src/renderer/remote.js 16:19-38 @ ../node_modules/@electron/remote/dist/src/renderer/index.js 27:13-32 @ ../node_modules/@electron/remote/renderer/index.js 1:0-48 @ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/App.vue?vue&type=script&lang=js 2:0-52 10:6-22 14:6-22 18:6-22 22:6-22 @ ./src/App.vue?vue&type=script&lang=js 1:0-189 1:0-189 1:190-368 1:190-368 @ ./src/App.vue 2:0-54 3:0-49 3:0-49 9:49-55 @ ./src/main.js 2:0-28 3:10-13
ERROR in ../node_modules/electron/index.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'E:\programing\electron\chapter1\node_modules\electron'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
webpack compiled with 2 errors
What is expected?
如何解决这个问题
What is actually happening?
解决问题