forge icon indicating copy to clipboard operation
forge copied to clipboard

[electron-forge make] EPERM: operation not permitted, rmdir.

Open 0x5374656c6c6172 opened this issue 1 year ago β€’ 20 comments

Pre-flight checklist

  • [X] I have read the contribution documentation for this project.
  • [X] I agree to follow the code of conduct that this project uses.
  • [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

7.2.0

Electron version

28.0.0

Operating system

Windows 11 Home

Last known working Electron Forge version

No response

Expected behavior

Be able to use electron-forge make / npm without EPERM errors.

Actual behavior

I am attempting to follow the "Quick Start > Package and distribute your application" guide provided by the Electron documentation. However, I am encountering the following error: EPERM: operation not permitted, rmdir 'C:\Users\user\AppData\Local\Temp\electron-packager\tmp-u5kZtS\resources\app\node_modules.electron-vy9FvFgv\dist'.

2

Steps to reproduce

npm run make

or

npx electron-forge make

Additional information

I have explored various solutions to address this issue, including:

  • Running the process both as an administrator and a regular user.
  • Executing npm cache clean --force and npm cache verify.
  • Changing the TEMP path to a location on a non-system drive.
  • Rebooting the computer under different states.
  • Attempting the use of YARN, resulting in the same error.
  • Adjusting versions of Node, NPM, and electron-forge with combinations such as: Node: v21.5.0, v20.10.0, v18.19.0, v9.11.2. NPM: v10.2.3, v4.x.x, v5.x.x. Electron-forge: v6.0.x.

To resolve the issue, I attempted to delete the empty folder created by electron-forge in the TEMP directory using rmdir "path" as specified in an error. However, I encountered the error Access is denied., being an administrator with the necessary permissions. Using rmdir /s /q "path" successfully removes a folder. I'm concerned that a library might be incorrectly using a command to delete a directory.

1

0x5374656c6c6172 avatar Dec 21 '23 16:12 0x5374656c6c6172

Facing same issue when using package command

navdeepm20 avatar Dec 23 '23 18:12 navdeepm20

Facing same issue when using package command

Yes, I have encountered a similar issue with package command too. electron-forge utilizes the system's temporary directory, and when trying to delete folders within it, it lacks the necessary permissions.

This is likely due to the outdated version of rimraf being used by electron-forge. I attempted to use the same version of the rimraf package globally as electron-forge when deleting a folder, and I encountered the same error that electron-forge was facing β€” being unable to delete the folder with EPERM error. However, when I updated rimraf from version 3.x.x to 5.0.5, the folder was successfully deleted.

0x5374656c6c6172 avatar Dec 23 '23 20:12 0x5374656c6c6172

Got it, but weird thing is that I have two apps running electron forge. One is still working fine but other started giving me issue suddenly. I guess after a windows update. I checked rimraf version in both apps and it's same in both apps. Also may I know how you updated the internal dependency rimraf

navdeepm20 avatar Dec 24 '23 11:12 navdeepm20

Got it, but weird thing is that I have two apps running electron forge. One is still working fine but other started giving me issue suddenly. I guess after a windows update. I checked rimraf version in both apps and it's same in both apps. Also may I know how you updated the internal dependency rimraf

When I globally installed rimraf with the version matching that of electron-forge (3.X.X), I attempted to delete a folder that electron-forge couldn't delete, resulting in the same EPERM error. However, upon updating rimraf to the latest global version (5.0.5), I successfully removed the folder using rimraf <path>.

0x5374656c6c6172 avatar Dec 24 '23 21:12 0x5374656c6c6172

But manually removing folder is not working in my case. I thought it's the prePackage hook and I tried deleting it manually the whole temp electron-packager directory but electron-forge is failing then in the postPackage hook.

navdeepm20 avatar Dec 26 '23 06:12 navdeepm20

Any update on this issue? I am using WSL to package builds for now!!

navdeepm20 avatar Jan 08 '24 06:01 navdeepm20

Any update on this issue? I am using WSL to package builds for now!!

No updates.

0x5374656c6c6172 avatar Jan 08 '24 10:01 0x5374656c6c6172

Why the maintainers are not responding? It's been 3 weeks. 🫑

navdeepm20 avatar Jan 08 '24 10:01 navdeepm20

Why the maintainers are not responding? It's been 3 month.

Umberto-Lago avatar Apr 13 '24 18:04 Umberto-Lago

I was having the same problem with EPERM in the %temp% folder with "@electron-forge/cli":"^7.4.0":

An unhandled rejection has occurred inside Forge:
Error: EPERM: operation not permitted, rmdir 'C:\temp\electron-packager\tmp-NmAfcr\resources\app'

I had created an app from scratch via wrapper as indicated in the documentation: npm init electron-app@latest my-app -- --template=webpack

I've tested all the suggested workarounds (cache clear, etc...) without effect, no matter how many times I delete the folder with error or run as administrator.

The only solution I had was to create an app manually with version 6 of @electron/forge:

npm install -g @electron-forge/[email protected]   
npx electron-forge init --template=webpack 

That way my app builds normally without errors:

PS C:\Users\xxxxxxx\Documents\GitHub\teste-electron2> npm run make

> [email protected] make
> electron-forge make

βœ” Checking your system
βœ” Loading configuration
βœ” Resolving make targets
  β€Ί Making for the following targets: squirrel
βœ” Running package command
  βœ” Preparing to package application
  βœ” Running packaging hooks
    βœ” Running generateAssets hook
    βœ” Running prePackage hook
      βœ” [plugin-webpack] Preparing native dependencies
      βœ” [plugin-webpack] Building webpack bundles
  βœ” Packaging application
    βœ” Packaging for x64 on win32 [2s]
  βœ” Running postPackage hook
βœ” Running preMake hook
βœ” Making distributables
  βœ” Making a squirrel distributable for win32/x64 [32s]
βœ” Running postMake hook
  β€Ί Artifacts available at: C:\Users\xxxxxx\Documents\GitHub\teste-electron2\out\make

I hope it helps. My repo: https://github.com/AlencarGabriel/example-electron-with-fast-design

AlencarGabriel avatar Apr 22 '24 04:04 AlencarGabriel

For some reason (without having changed anything) make stopped working. Even in the version that used to work.

What I realized is that the directory: %temp%\electron-packager\win32-x64\Appxxxxx\resources\app is created with some protection or limitation, that I can't even remove the folder by running a simple delete script via node:

image

All other files and folders are removed, except \app

AlencarGabriel avatar Apr 30 '24 19:04 AlencarGabriel

I don't want to push it, but I think the problem might be Node.

I just changed remove to removeSync() in my example above and the folder was successfully removed.

I looked at the fs-extras repo (used in electron-forge) and I didn't see anything else between them, in the end it's a call to the Node default fs.

I played around with my node_modules and changed all the references from fs.remove() to fs.removeSync() in the electron-package folders, and magically the build worked correctly. πŸš€

What I still don't understand is why some repositories (using the same versions of dependencies) work and others don't, even on the same machine. And why it started happening out of the blue.

AlencarGabriel avatar Apr 30 '24 21:04 AlencarGabriel

When should we expect an update for this?

navdeepm20 avatar May 11 '24 19:05 navdeepm20

I don't want to push it, but I think the problem might be Node.

I just changed remove to removeSync() in my example above and the folder was successfully removed.

I looked at the fs-extras repo (used in electron-forge) and I didn't see anything else between them, in the end it's a call to the Node default fs.

I played around with my node_modules and changed all the references from fs.remove() to fs.removeSync() in the electron-package folders, and magically the build worked correctly. πŸš€

What I still don't understand is why some repositories (using the same versions of dependencies) work and others don't, even on the same machine. And why it started happening out of the blue.

Maybe it's a permission issue because you didn't run PowerShell as an administrator? It shouldn't be a Node.js problem.

I solved the issue by running the make command as an administrator.

minikinl avatar Jun 03 '24 02:06 minikinl

I don't want to push it, but I think the problem might be Node. I just changed remove to removeSync() in my example above and the folder was successfully removed. I looked at the fs-extras repo (used in electron-forge) and I didn't see anything else between them, in the end it's a call to the Node default fs. I played around with my node_modules and changed all the references from fs.remove() to fs.removeSync() in the electron-package folders, and magically the build worked correctly. πŸš€ What I still don't understand is why some repositories (using the same versions of dependencies) work and others don't, even on the same machine. And why it started happening out of the blue.

Maybe it's a permission issue because you didn't run PowerShell as an administrator? It shouldn't be a Node.js problem.

I solved the issue by running the make command as an administrator. `

@minikinl

I think that if it was a permission problem it should also happen with fs.removeSync(), but in this scenario I mentioned the problem only occurred with fs.remove()`.

AlencarGabriel avatar Jun 03 '24 12:06 AlencarGabriel

Also getting this issue on Windows CI. The workaround was to downgrade Forge to 6.4.2.

UPDATE: Fixed properly now. It was caused by turborepo running two forge builds in parallel.

goosewobbler avatar Jun 23 '24 16:06 goosewobbler

Also getting this issue on Windows CI. The workaround was to downgrade Forge to 6.4.2.

UPDATE: Fixed properly now. It was caused by turborepo running two forge builds in parallel.

Would you be so kind to write a tutorial on how to do it?

ancym0n avatar Aug 29 '24 17:08 ancym0n

Would you be so kind to write a tutorial on how to do it?

Sure - if you're using Turborepo and running multiple forge builds, ensure that the builds are run consecutively. You can do this with --concurrency=1, or by setting each forge build to depend on another. In my project there are two forge builds, one for CJS and one for ESM, they were running in parallel which resulted in this error, the fix was to make the CJS build dependent on the ESM build.

goosewobbler avatar Aug 29 '24 20:08 goosewobbler

Had the same issue on previously working application, but using some of the info above from @AlencarGabriel I've got a workaround that allowed me to make the app. Possibly some Windows update has broken this functionality (I'm on Win11)?

For electron-forge v7.5.0 Edited two of the files in ..\node_modules\@electron\packager\dist\ platform.js and universal.js Changed all references from the command fs_extra_1.default.remove to fs_extra_1.default.removeSync Then re-run npm run make and it worked correctly.

Alternatively, if you're on electron-forge v6.x (or you want to downgrade with npm install @electron-forge/[email protected]), you need to edit three of the files in \node_modules\electron-packager\src

universal.js, platform.js & index.js and replace fs.remove with fs.removeSync in all cases.

VirtualColossus avatar Oct 09 '24 11:10 VirtualColossus

I am facing the same problem when running the package command.

I have Windows 10 and @electron-forge/cli”:β€œ^7.5.0.

First tried, as @VirtualColossus advised, changing fs_extra_1.default.remove to fs_extra_1.default.removeSync in the platform.js and universal.js files, but that didn't help.

And how I solved it in my case.

Thinking that the problem might be related to deleting temporary files, I went to C:\Users\SHTF\AppData\Local\Temp\electron-packager\tmp-oMtQDG\resources\app and found the last folder empty. I decided to manually delete the electron-packager folder and all its contents.

After that I ran the package command again and everything workedπŸ€—. The electron-packager folder appeared in the Temp folder again, but it was empty without tmp-oMtQDG\resources\app or similar.

I don't know why I had to delete it all manually. If anyone has any ideas, I will be glad to hear them.

SheeetFace avatar Oct 18 '24 09:10 SheeetFace

same issue

ycjcl868 avatar Jan 20 '25 12:01 ycjcl868

Why the maintainers are not responding? It's been 3 month.

And it's been a year! The few apps that I'm currently running Forge on are able to package in CI on Electron Forge 7 with no issues. I currently don't have a repro case after running the package command on a fresh repo on Windows 11.

There might be an issue with your specific device setup that makes this hard to debug.

erickzhao avatar Jan 31 '25 23:01 erickzhao

I upgraded the node version and then only it worked I tried all solutions provided in this thread but only upgradation of node version worked.

Amit-Dagar avatar Nov 14 '25 09:11 Amit-Dagar