Reputation: 471
I get this error in my app:
Error: EPERM: operation not permitted, open 'C:\Program Files (x86)\Full Menu\db\main.json'
The app I have is built with electron-boilerplate. I am using this function to get the path to the root of the app:
path.dirname(process.execPath)
And this is the script that writes the file:
fs.writeFile(apath + '/db/' + elem + '.json', JSON.stringify(results)
I know what the problem is: permissions. But how could I get this working without running the app as an administrator?
Upvotes: 46
Views: 132932
Reputation: 678
I've faced recently such a problem in my code. After a harsh searching for solution, finally I've just build the project and after that, everything worked properly. I've just run the following code.
yarn build
or
npm run build
I don't exactly know, if it works for everyone facing such a problem, but hope it will.
Upvotes: -1
Reputation: 21
I was facing the same problem using the following software:
I was able to solve it opening GitBash as admin
Upvotes: 0
Reputation: 49
If you are facing this issue on Windows 10, then please try the following:
If nothing above works, then try the following: https://appuals.com/how-to-fix-folder-keeps-reverting-to-read-only-on-windows-10/.
Hope this would of help.
Upvotes: 4
Reputation: 11
I had the same problem, when i tried to create and write to a file using NodeJS. I thought it had to do with my windows file/folder access permissions, but after restarting my computer and running the code again, I still got the same error.
However, this time around my antivirus gave me a pop-up message also, stating that it blocked permission for Node.exe to write or open files. So once I flagged Node.exe as safe for my anti-virus program (Avast).
It worked for me. Disabling my antivirus could've also temporarily fixed it, I guess.
Upvotes: 0
Reputation: 456
On my Windows 10 machine, I encountered this error when running an old Node JS project. I think Node version 10.16.
In any case, it was trying to modify a dotfile in my project. Be sure that the file isn't hidden on Windows. After unchecking the hidden option in the file properties pop up. Everything worked.
So to fix:
Upvotes: 21
Reputation: 5161
this is not an exact answer but may help:
i think if you want to read
or readSync
a file that doesn't exist you will encounter an EPERM
error...
in many programming languages, any permission related error may not directly means an actual permission issue
for example in PHP
Folders (not files) must delete by php rmdir()
method but if you want to do that with unlink()
, u will encountered with a wrong Warning message that says "permission denied"
Upvotes: 1
Reputation: 593
I face this issue when I was deleting a file/folder.
Solution:
Just restart your code editor/ terminal Or Restart your computer
Upvotes: 6
Reputation: 872
If you have the file that you can't open or modify mounted as a volume in docker restarting docker should fix the issue.
Upvotes: 16
Reputation: 878
I had this issue too. I'm using TFS (or VSO, Azure DevOps, etc.) for source control. I was trying to compile from .scss to .css and it couldn't open my .css. I just needed to right-click on my .css file and Check Out for Edit...
Upvotes: 1
Reputation: 27
I had the error because i have already open the file before
var stream = fs.createWriteStream(outputFileName, {flags:'a'})
var output = fs.createWriteStream(outputFileName, {flags:'a'})
Upvotes: 0
Reputation: 900
If you use windows 10, you must turn off Ransomware protection. Ransomware protection will prevent all folder and file changes.You can turn off it in Windows Security Center. See screenshot below:
Upvotes: -3
Reputation: 836
i had to run the node command prompt as administrator and that fixed the issue.
Upvotes: 10
Reputation: 16956
For the benefit of searchers; I has this error. I added full permissions for Everyone
as a test, but that didn't fix it. The issue was that the file was set to readonly
(by source control).
Unchecking the readonly
option in the file properties fixed the issue.
Upvotes: 54
Reputation: 200
I think that you must change the permissions recursively to the file so the user executing your script can read / write this file.
https://fr.wikipedia.org/wiki/Chmod
Upvotes: 0