Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: EPERM: operation not permitted, open 'C:\Users\username\.node_repl_history' #5261

Closed
t0lkman opened this issue Feb 16, 2016 · 36 comments
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform.

Comments

@t0lkman
Copy link

t0lkman commented Feb 16, 2016

On Windows 7 for node 5.5.0 if ".node_repl_history" has hidden attribute, node fails to open.

@mscdex mscdex added repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform. labels Feb 16, 2016
@Fishrock123
Copy link
Contributor

@t0lkman as an intermediate fix, set the env variable: NODE_REPL_HISTORY=" "

@mrnerdhair
Copy link

As a workaround, you can put .node_repl_history in a folder, set the folder hidden, create a symlink (with mklink) called .node_repl_history to the real file in the hidden folder, and then use attrib /l +h to set the hidden attribute on the symlink but not the file itself. This is stupid, but at least it declutters my user folder.

@Fishrock123 Fishrock123 added the good first issue Issues that are suitable for first-time contributors. label Mar 14, 2016
@Fishrock123
Copy link
Contributor

Maybe we should just continue if there is an error and warn in the repl?

@mrnerdhair
Copy link

The problem is that the error should not occur. Just because the file is set hidden should not cause a permissions error.

@thefourtheye
Copy link
Contributor

@t0lkman Few of us don't use. So can you please show the actual error stack trace or explain in detail what exactly happens?

Edit: nvm. I see the title now.

@be5invis
Copy link

And I see this: http://stackoverflow.com/questions/2246990/how-do-i-write-to-a-hidden-file
So maybe when saving repl history, Node should temporary unhide it, save, and re-hide it.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 14, 2016

I think printing a warning is the best bet. If the user has been fiddling with the file, maybe they don't want Node writing to it. Or, maybe they hadn't realized, and printing a warning will help them fix it.

@t0lkman
Copy link
Author

t0lkman commented Mar 14, 2016

@cjihrig I don't agree with you, I always hide all unnecessary system files on Windows, hidden files shouldn't be considered "read only" hence I don't need any warnings

@mrnerdhair
Copy link

The file is supposed to be hidden. On POSIX systems, the file name starting
with a dot is the marker for a hidden file, so it should be hidden by
default. If a user didn't want it to be writable, they would have set the
read-only bit--which is right next to the checkbox for the hidden bit.

On Mon, Mar 14, 2016 at 6:11 PM Colin Ihrig notifications@github.com
wrote:

I think printing a warning is the best bet. If the user has been fiddling
with the file, maybe they don't want Node writing to it. Or, maybe they
hadn't realized, and printing a warning will help them fix it.


Reply to this email directly or view it on GitHub
#5261 (comment).

@Fishrock123 Fishrock123 added discuss Issues opened for discussions and feedbacks. and removed good first issue Issues that are suitable for first-time contributors. labels Mar 15, 2016
@Fishrock123
Copy link
Contributor

cc @nodejs/platform-windows is there some special way we should attempt to open files that might be hidden on windows?

@mrnerdhair
Copy link

No, that's the problem: I don't know of any other program that has issues
opening hidden files on Windows, excepting the dos-era copy/move/del
commands on the command line, and those are designed that way for
compatibility reasons.
On Tue, Mar 15, 2016 at 4:43 PM Jeremiah Senkpiel notifications@github.com
wrote:

cc @nodejs/platform-windows
https://github.com/orgs/nodejs/teams/platform-windows is there some
special way we should attempt to open files that might be hidden on windows?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#5261 (comment)

@seishun
Copy link
Contributor

seishun commented Mar 16, 2016

Node.js does have checks for file availability and fails gracefully if, for example, the file is set to read-only. However, for some reason it opens and closes the file three times - first as 'a+', then as 'r', then as 'w'.

The problem is the third one, where there aren't any checks anymore. Trying to open a hidden file in 'w' mode is an error in Node.js, in Python (great explanation there), in C's fopen (at least using CRT) and I assume in many other languages too.

I can think of the following solutions:

  • Use a different mode instead of 'w', maybe 'r+'
  • Fix libuv to automatically pass the FILE_ATTRIBUTE_HIDDEN flag if needed (would make it inconsistent with other languages)
  • Open the file only once and fail gracefully if it's hidden
  • Add failure checks to all three open calls

@joeyespo
Copy link
Contributor

This also happens on Windows 10 with node v6.2.1.

@joeyespo
Copy link
Contributor

Another workaround is to set the NODE_REPL_HISTORY ENV variable to another location. This is what I've been doing.

@wagnlinzh
Copy link

add code in the file .node_repl_history and try ?

exit
1+1

@ackvf
Copy link

ackvf commented Aug 9, 2016

Still an issue, even with other files

fs.js:549
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EPERM: operation not permitted, open 'C:\Users\Qwerty\.babel.json'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.writeFileSync (fs.js:1156:15)
    at save (C:\repos\b2bportal-widgets\node_modules\babel-core\lib\api\register\cache.js:35:19)
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:968:3

@ccoenen
Copy link

ccoenen commented Jan 16, 2017

Still an issue, Windows 10 64 bit with node v7.4.0:

C:\somewhere\> node
> bootstrap_node.js:148
              throw err;
              ^

Error: EPERM: operation not permitted, open 'C:\Users\<username>\.node_repl_history

@ccoenen
Copy link

ccoenen commented Jan 16, 2017

Why is this marked as "discuss"? There's not really anything to discuss. I know no other tool with this behaviour? It is clearly simply a bug.

@joyeecheung
Copy link
Member

joyeecheung commented Jan 18, 2017

From #5261 (comment) and #7005 I think this is a bug. The fix should be in the repl module. #7005 provides a potential fix but it looks stalled for CI failure. I think if someone using Windows has a fix (or can fix it by trying #5261 (comment)) they can feel free to open another PR.

@joyeecheung joyeecheung added confirmed-bug Issues with confirmed bugs. and removed discuss Issues opened for discussions and feedbacks. labels Jan 18, 2017
@lance
Copy link
Member

lance commented Jan 19, 2017

@joyeecheung yes, I have essentially dropped the ball on #7005. I agree that this is a bug which needs to be fixed, but I was unable to resolve the Windows failures on CI and could not get any real resolution on how to move forward. If you or anyone else has recommendations for resolving this on those Windows builds, I would be happy to pick the PR back up again and run with it. But without that, I am not sure what to do since I really have very little knowledge of Windows systems.

@bzoz bzoz closed this as completed in bb041ea Apr 20, 2017
@bzoz
Copy link
Contributor

bzoz commented Apr 20, 2017

Fixed in bb041ea

evanlucas pushed a commit that referenced this issue Apr 25, 2017
On Windows when REPL history file has the hidden attribute node will
fail when trying to open it in 'w' mode. This changes the mode to
'r+'. The file is guaranteed to exists because of earlier open call
with 'a+'.

Fixes: #5261
PR-URL: #12207
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this issue May 1, 2017
On Windows when REPL history file has the hidden attribute node will
fail when trying to open it in 'w' mode. This changes the mode to
'r+'. The file is guaranteed to exists because of earlier open call
with 'a+'.

Fixes: #5261
PR-URL: #12207
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this issue May 2, 2017
On Windows when REPL history file has the hidden attribute node will
fail when trying to open it in 'w' mode. This changes the mode to
'r+'. The file is guaranteed to exists because of earlier open call
with 'a+'.

Fixes: #5261
PR-URL: #12207
Reviewed-By: James M Snell <jasnell@gmail.com>
gibfahn pushed a commit that referenced this issue Jun 18, 2017
On Windows when REPL history file has the hidden attribute node will
fail when trying to open it in 'w' mode. This changes the mode to
'r+'. The file is guaranteed to exists because of earlier open call
with 'a+'.

Fixes: #5261
PR-URL: #12207
Reviewed-By: James M Snell <jasnell@gmail.com>
gibfahn pushed a commit that referenced this issue Jun 20, 2017
On Windows when REPL history file has the hidden attribute node will
fail when trying to open it in 'w' mode. This changes the mode to
'r+'. The file is guaranteed to exists because of earlier open call
with 'a+'.

Fixes: #5261
PR-URL: #12207
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Jul 11, 2017
On Windows when REPL history file has the hidden attribute node will
fail when trying to open it in 'w' mode. This changes the mode to
'r+'. The file is guaranteed to exists because of earlier open call
with 'a+'.

Fixes: #5261
PR-URL: #12207
Reviewed-By: James M Snell <jasnell@gmail.com>
@aminehadded
Copy link

you have to open the cmd as administrator and try again with npm install

@ccoenen
Copy link

ccoenen commented Nov 10, 2018

As a blanket statement, that is really bad advice. Please only run commands with administrator privileges or sudo if you really know what you're getting yourself into.

@imthenachoman
Copy link

@seishun So, based on what you're saying, node can't read hidden files in Windows? So we just need to leave files un-hidden?

@alidavodii
Copy link

alidavodii commented Dec 11, 2019

hi my friends , go to c:/users/{pc name}/
show hidden file
properties .yarnrc
hidden uncheck
good luck
Annotation 2019-12-11 102530

@imthenachoman
Copy link

@alidavodii Yes. But I’m interested in getting Node to work even if the file is hidden in Windows. However, it appears as it isn’t easily possible. Oh well.

@BridgeAR
Copy link
Member

It is possible to read hidden files. The file mode just must be set accordingly.

@imthenachoman
Copy link

@BridgeAR Even when the file mode allowed read I was getting that EPERM error. I had to unhide the file from Windows to get rid of the error.

@BridgeAR
Copy link
Member

@imthenachoman it would be good to get further information about your OS and what code you executed to further look at that. As it stands right now, we can't do anything to improve the situation in case there's indeed a bug left (which might might be).

@imthenachoman
Copy link

@BridgeAR I am on Windows 10. But I don't think there is anything that needs to be investigated. If a file is hidden then Node can't access it. In my case I am getting the error when trying to use clasp. If the file in question is hidden (through Windows) I get the EPERM error. If the file in question is not hidden I do not get the error. I don't understand all of the technical aspects but based on what I read it sounds like because of Windows limitations, Node cannot access Windows hidden files. So I think its case closed -- unless my understanding of what I read is wrong.

@BridgeAR
Copy link
Member

@imthenachoman ideally we'll have a consistent behavior across all operating systems. I do wonder if it's possible to handle this case transparently for users on Windows. I am not a Windows user though and can't look into it on my own.

@imthenachoman
Copy link

I don't really know/use Node.js so I don't know what to look for but if there is something you want me to try, investigate, look at, etc. I can. Like are there more verbose log files anywhere that show what Node was trying to do when it looked for that file?

@dibakar95
Copy link

hi my friends , go to c:/users/{pc name}/
show hidden file
properties .yarnrc
hidden uncheck
good luck
Annotation 2019-12-11 102530

What should I do next

@bzoz
Copy link
Contributor

bzoz commented Mar 30, 2020

@dibakar95 you should go to yarn issue tracker, this one is for Node

@demateu
Copy link

demateu commented Jun 12, 2021

I changed the permission to the project folder and it worked for me:
chmod -R 777 project_folder-name

@sryze
Copy link

sryze commented Jan 1, 2022

Related: libuv/libuv#3380

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.