Yarn: Windows fails with EPERM: operation not permitted, all files are read-only

Created on 13 Oct 2016  路  44Comments  路  Source: yarnpkg/yarn

Do you want to request a _feature_ or report a _bug_?
Bug

What is the current behavior?
When performing any operation with yarn (add for instance) it errors with:

EPERM: operation not permitted, open 'C:\foo\node_modules\firebase\app-node.js'
at Error (native)

If the current behavior is a bug, please provide the steps to reproduce.

  1. Use Windows :(
  2. Use yarn
  3. Failure

To fix the issue, right click the node_modules folder and un-check "Read-only". Wait. Re-run yarn command. Now it works, like magic! After yarn is done, all files are back to being read-only though.

What is the expected behavior?
Shouldn't have to mark the files as readable.

Please mention your node.js, yarn and operating system version.
node v6.3.1
yarn v0.15.1
Windows 10 (anniversary edition)

cat-bug os-windows triaged

Most helpful comment

Encountered this error because I tried to execute a yarn command while node server was running. Whoops! HTH someone else.

All 44 comments

To fix the issue, right click the node_modules folder and un-check "Read-only".

Is Yarn marking node_modules as readonly, or is something else doing that? I can't repro on Windows with a brand new app (ie. yarn init && yarn add react)

Hi @Daniel15

Could you please try this in a clean directory?

yarn init
yarn add firebase
yarn add react

The last command gives me:

C:\Dev\yarntest>yarn add react
yarn add v0.15.1
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
error EPERM: operation not permitted, open 'C:\Dev\yarntest\node_modules\firebase\app-node.js'
    at Error (native)
info Visit http://yarnpkg.com/en/docs/cli/add for documentation about this command.

I'm not sure if it's something the firebase packages does?

For clarification; I tried the same steps but with react and eslint and didn't see the same error.

Thanks for the information! I can replicate the issue on Windows but not on Debian Linux.

I would say this is more of a _critical error_ as it prevents even basic use of Yarn in any project using firebase module.

Removing _read-only_ flag recursively works, but only temporarily. Even running just yarn reruns whole linking dependencies phase and returns these _read-only_ flags back.

Creating fresh project with yarn init and installing any single dependency sets _read-only_ flag to all directories (not files) starting from node_modules. However in case of firebase module, the files are also _read-only_ for some reason. Doing same thing with NPM does not set _read-only_ to files.

Yes this is quite annoying.

@Daniel15
Another problem I have I install the package and on postinstall step it sets chmod some-file 400, and while some operations yarn fail with a like error on this file, (if I set permissions to 644 it runs ok). So I hope you fix original issue and my issue will gone too.

@Tapppi (quote from issue)

P.S. Regarding #992, you could probably write a oneliner "postinstall" script to fix the permissions after every install.

That would kinda erase usefulness of Yarn, don't you think? Removing those read-only flags makes Yarn do whole linking process again. Only performance save would about using cache instead of downloading over the network every time.

@FredyC I fail to see how a postinstall script erases yarns usefulness? It's still most likely multiple times faster than npm when installing, and has a lock file. If that makes yarn unpreferable for you, I would think yarn is not preferable anyways in its current form?

Encountering this as well. Nothing special about my project, I'm just getting around it by blowing out my node_modules folder for new packages for now.

Hopefully this resolves soon, thank goodness yarn is so damned fast! ;)

Well this is interesting. If you download actual tarball of the firebase module, those read-only attributes are already there! ... https://registry.npmjs.org/firebase/-/firebase-3.4.1.tgz

That means it's not exactly Yarn fault. I assume that what NPM does differently is to actually remove that flag upon installation. Essentially that might be solution that Yarn should do as well because you never know what other module can be affected like that.

I've actually tried to publish my own package to NPM with read-only flag set on the one file. Sadly that's not the source of the problem. Files are published without the flag.

So I've filed support request with Firebase to see if there is something they can change in their publishing process.

Can we hope that in future Yarn release this case will be dealt with, using NPM approach or otherwise.

Just a FYI, it will also work if you remove firebase first, then add your required packages and at last add firebase back. So is Yarn updating the permissions when firebase is removed?

@vijay-stayntouch No, Yarn does nothing about it. Main problem is that if you have firebase there with read only flags and the "linking dependencies" process has to be executed for some reason, it is unable to touch these files and fails. Although I am bit unsure how it's possible that Yarn can actually delete those files with read-only flags.

Hey, Firebase engineer here. We are going to fix this on our end by making sure our next release no longer contains read-only files. That being said, this does seem like unexpected behavior and probably should get fixed across the board for Yarn, as it is in npm. Thanks!

Is this the same issue as #872?

Good news to everyone who has trouble with this. There is a new firebase module 3.6.2 without read only flags and it works flawlessly now.

I recommend closing this one in favor of #961 which is more generic and related to Yarn only.

@FredyC Great news!

The question still hangs up in the air that if any other packages makes their code read-only. The same issue will happen again.

@vijay-stayntouch Yea, that's what #961 should try to solve really.

I have the same issue with yarn add react-hot-loader --dev it says :

yarn add v0.20.3
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
error An unexpected error occurred: "EPERM: operation not permitted, utime '/home/syd/Work/taxibs/zaher/node_modules/source-map/README.md'".
info If you think this is a bug, please open a bug report with the information provided in "/home/syd/Work/taxibs/zaher/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

I'm do a yarn cache clean and exec the yarn add ... again but the problem still there.
I'm on the ubuntu 16.04
node v6.9.4 & npm v3.10.10

I was getting the same issue - the only solution that worked for me was to use rimraf node_modules to delete the node_modules folder then reinstall all packages using yarn

I find this issue from time to time installing packages with npm or yarn, my workaround is going to file manager, right click on /node_modules main folder, selecting properties, and check-uncheck "read-only". You can do it also using attrib in command line. Then you retry installation and it works.

Encountered this error because I tried to execute a yarn command while node server was running. Whoops! HTH someone else.

Tried multiple solutions presented (incl. read-only uncheck) - doesnt work
versions
node v6.11.1
yarn v0.27.5
Windows 10

error: "EPERM: operation not permitted, unlink 'D:\urp\node_modules\node-sass\vendor\win32-x64-48\binding.node'"

_ran:_
$yarn check --integrity

_received:_
error Lockfile does not contain pattern: "material-ui@^0.19.0"
error Lockfile does not contain pattern: "[email protected]"
error Lockfile does not contain pattern: "npm-run-all@^4.1.1"
error Lockfile does not contain pattern: "react@^15.6.1"
error Lockfile does not contain pattern: "react-dom@^15.6.1"
error Lockfile does not contain pattern: "react-router-dom@^4.2.2"
error Lockfile does not contain pattern: "react-tap-event-plugin@^2.0.1"
error Couldn't find an integrity file

Any help will be great!

yep, it sometimes sucks while doing in Win (like developing Ionic2/3 in Win, permanently throwing EPERM errors for i.e installing/mod npm packs and other stuff); it may be cuzed by antivirus software; unchecking read only attr from all node_modules;
Also, try to add .npmrc file to your forlder (c:/users/) with content unsafe-perm=true; add the same file to your project's root; last resort: run powershell as admin and elevate with Start-Process powershell -Verb runAs - gonna open new elevated powershell window, which should be able to operate

On Windows, be sure to run the Command Prompt "As Administrator". ::facepalm::

Tried everything listed here - the only way I was able to fix it was:

npm install -g rimraf
rimraf node_modules

as suggested by @domjtalbot.

also this happens when you have two instance of yarn running trying to install packages in different projects

happens to me too, npm 5.8.0, and the only one working is pointed by @domjtalbot and @James-E-Adams

I run into the same issue when I have a server running with nodemon, then adding a package yarn add bcrypt. With @rmorrise 's comment I fix my problem.Never know the server running will affect installing.

@rmorrise +1, would be logical if yarn could detect such circumstance and throw a meaningful warning instead.

For info: I had the same issue after cancelling the installation of a package (ctrl+c), and trying to install another package afterwards. I also had a server running but it didn't cause errors when I added other packages before.

download (1)

I've run into this error quite a few times now and only a reboot of Windows helped.

I've had the same problem. The reason caused this bug was running create-react-app development server in ubuntu for windows bash. Stopping the server solved the problem.

download (1)

I've run into this error quite a few times now and only a reboot of Windows helped.

Usually i prefer downvoting such answers, but this was literally the only thing that worked for me 馃う鈥嶁檪

download (1)

I've run into this error quite a few times now and only a reboot of Windows helped.

This indeed did the trick for me...

At least for me, this seems to be caused by having vscode open.

Make sure your app(angular, react, etc...) is turned off before npm install

@ScottGuymer

I can't believe this works

thank you for your solution

@Gameghostify me either 馃槃

You're welcome.

Check if you have a node process running, shut if off and try again

I was running yarn from a vscode terminal so I restarted vscode and that did the trick

yep, it sometimes sucks while doing in Win (like developing Ionic2/3 in Win, permanently throwing EPERM errors for i.e installing/mod npm packs and other stuff); it may be cuzed by antivirus software; unchecking read only attr from all node_modules;
Also, try to add .npmrc file to your forlder (c:/users/) with content unsafe-perm=true; add the same file to your project's root; last resort: run powershell as admin and elevate with Start-Process powershell -Verb runAs - gonna open new elevated powershell window, which should be able to operate

IT REALLY WORKED. THANK YOU.

@Gayathri-K-2000 Can you provide more details please? I'm facing same issue but didn't work. Please provide example of what you did if possible. Thank you!

@Gayathri-K-2000 Can you provide more details please? I'm facing same issue but didn't work. Please provide example of what you did if possible. Thank you!

I unchecked 'read only' from properties of node modules and ran in cmd as administrator. It works.

Check if you have a node process running, shut if off and try again

That indeed was my problem here as well. Same goes for react apps, e.g. when you are prompted to install node-sass - you can't do it while your app is running. Thanks all!

Was this page helpful?
0 / 5 - 0 ratings