Cannot find module 'fs/promises' Electron JS
Solution 1
I experienced this issue a few days ago as well. I realized that trying to fix another issue, I deleted the node_modules
folder and the package-lock.json
file, then run the npm install
command. This made the build to fail with 'fs/promises'. There are 2 solutions to this issue:
- Download the latest stable Node version. This should have the 'fs/promises' module and will fix the issue.
- Delete the
node_modules
folder and bring back the oldpackage-lock.json
file to ensure that the package versions remain the same. Then run thenpm install
command and the issue should be fixed.
Solution 2
downgrade electron "electron-builder": "^22.10.5", or upgrade nodejs to 14+ v
Solution 3
downgrade to "electron-builder": "~22.10.5"
is working for me
Solution 4
In that case i fix the problem in that way: const fs = require('fs').promises;
instead of: const fs = require('fs/promises');
Solution 5
In my case I was using nvm
to manage multiple node versions.
During the npm package installation, and throughout development, I used Node v14
but for some reason, my terminal was pointing to Node v12
when I tried bundling my program afterwards.
Switching it back to Node v14
using nvm use 14
solved my issue.
So make sure you're using the correct node version.
stillborn1
Graduated in computer engineering at the Autonomous University of Barcelona
Updated on April 28, 2022Comments
-
stillborn1 about 2 years
Good morning,
I have created a program in Vue JS, this connects with an API that I have created in a main.js file to execute system commands.
The problem I have is that when compiling for production with electron I get the following error:
I use the command npm run electron: build
When I use npm run electron:serve work without problems
Anyone have any idea why is the error and how to fix it? Thanks
-
Paul Franke almost 3 yearsI had the same issue .. Update to the newest nodejs-Version will fix this issue.
-
-
Boat over 2 yearsDowngrading the electron-builder version worked for me, with node 12.18.4. This should be the accepted answer since retrieving old package-lock.json is not going to work when installing everything first time.
-
Meekohi over 2 yearsUpgrading to node v14 worked for me. Thanks!
-
Peter Palmer over 2 yearsHey there, I did upgrade my NodeJS version and worked for me, I used terminal commands in order to upgrade in a faster way, you can follow the instructions here: stackoverflow.com/questions/8191459/how-do-i-update-node-js. Take into consideration that maybe other projects you have are incompatible with this new version you are installing, in that case, consider using NVM.