Cannot Find Module 'Fs/Promises' Electron Js
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...
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
7 Answers
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_modulesfolder and bring back the oldpackage-lock.jsonfile to ensure that the package versions remain the same. Then run thenpm installcommand and the issue should be fixed.
downgrade electron "electron-builder": "^22.10.5", or upgrade nodejs to 14+ v
downgrade to "electron-builder": "~22.10.5" is working for me
In that case i fix the problem in that way: const fs = require('fs').promises;
instead of: const fs = require('fs/promises');
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.
I had the same problem, after upgrading the electron-builder from v. 21.4.0 to 23.0.2, updated with the command:
sudo npm install -g electron-builder@23.0.2
I solved updating npm, and then node.js.
Update
npm:sudo npm install -g npm@latestInstall
nodejsfrom
Now it works with :
- Electron-builder: 23.0.2 (command
electron-builder --version) - Npm: 8.7.0 (command
npm --version) - Nodejs: v16.15.0 (command
node --version)
Upgrade to electron-updater@5.0.0. It has patch changes replacing fs/promises with fs-extra to support legacy versions of electron.