Can't resolve 'fs'
See original GitHub issueWith Angular 9 I get the following error:
ERROR in ../node_modules/electron/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\feren\Projects\[projectname]\node_modules\electron'
ERROR in ../node_modules/electron-log/src/transports/file/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\feren\Projects\[projectname]\node_modules\electron-log\src\transports\file'
ERROR in ../node_modules/electron-log/src/transports/file/file.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\feren\Projects\[projectname]\node_modules\electron-log\src\transports\file'
ERROR in ../node_modules/electron-log/src/transports/file/packageJson.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\feren\Projects\[projectname]\node_modules\electron-log\src\transports\file'
relevant part of app.module.ts:
import * as log from 'electron-log';
log.transports.file.level = false;
log.transports.ipc.level = 'info';
console.log = log.log;
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Module not found: Error: Can't resolve 'fs' in - Stack Overflow
I found a possible solution, that you have to put some configuration in one of the node_modules. But I think that is not...
Read more >How To Solve Module Not Found Can't Resolve 'fs' in Next.js
The Module not found : Can't resolve 'fs' error and similar issues most likely occur when you try to import a module that...
Read more >Can't resolve 'fs' error in Next.js and WebPack - Nsikak Imoh
The Module not found: Can't resolve 'fs' in Next.js error occurs when you import a Node.js module that is not available in the...
Read more >Module not found: Can't resolve 'fs' error [Solved] | bobbyhadz
The error "Module not found: Error: Can't resolve 'fs'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >Can't resolve 'fs' when bundle with webpack #447 - GitHub
I got this error when using the "fetch" library from npm. At first I got the same error but with other packages (...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a solution, follow this guide: https://developer.okta.com/blog/2019/12/09/angular-webpack (just the
Set Up Angular With Webpack
section), and in yourcustom-webpack.config.js
set the target toelectron-renderer
, like so:If you get the "Error: Can’t resolve ‘fs’ in … " in your Angular application after adding Electron-log try this:
In the renderer (a component) use code like this (note the window.require):
If using the maximegris/angular-electron starter you would probably want to put the instance of log in the ElectronService and access it through that, so you don’t have to write the window.require everywhere.
More info https://github.com/maximegris/angular-electron/issues/632#issuecomment-898484389 and https://github.com/maximegris/angular-electron#how-to-import-3rd-party-libraries
In main process just instantiate it normally and make sure to set nodeIntegration: true, and contextIsolation: false if you want to use Electron-log in renderer process.
/app/main.ts