Yarn: globally installed packages have incorrect permissions (EACCES)

Created on 14 Oct 2016  路  23Comments  路  Source: yarnpkg/yarn

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

What is the current behavior?
EACCES

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

Error: EACCES: permission denied, open '/root/.yarn-cache/.global/node_modules/arr-flatten/index.js'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at Object.Module._extensions..js (module.js:415:20)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/root/.yarn-cache/.global/node_modules/arr-diff/index.js:10:15)
    at Module._compile (module.js:409:26)

If the current behavior is a bug, please provide the steps to reproduce.
sudo npm i -g yarn
sudo yarn global add gulp
gulp

What is the expected behavior?
correct permissions

Please mention your node.js, yarn and operating system version.
Node v4.4.6
Yarn 0.15.1
Gentoo Stable

cat-bug needs-repro-script triaged

Most helpful comment

Also seeing the bug with yarn global v0.18.1. A workaround would be to manually give read access to everybody with:

sudo chmod a+r -R /usr/local/share/.config/yarn/global/

All 23 comments

Not gulp specific, globally installed packages are not usable because of incorrect permissions:

Do you want to request a feature or report a bug?
bug

What is the current behavior?
EACCES

manuelescudero@Manuel-Escudero ~/angular2> ng new project
fs.js:640
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EACCES: permission denied, open '/Users/manuelescudero/.yarn-cache/.global/node_modules/broccoli-viz/index.js'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Object.Module._extensions..js (module.js:578:20)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/manuelescudero/.yarn-cache/.global/node_modules/ember-cli/lib/models/builder.js:12:11)

If the current behavior is a bug, please provide the steps to reproduce.
brew update
brew install yarn
sudo yarn global add angular-cli
ng new project

What is the expected behavior?
correct permissions

Please mention your node.js, yarn and operating system version.
Node v6.8.1
Yarn 0.15.1
macOS Sierra 10.12

Can confirm this bug on Arch Linux

psykukumber@pklaptop:[~]$ sudo yarn global add npms-cli                       
yarn global v0.16.1
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed [email protected] with binaries:
      - npms
Done in 16.93s.
psykukumber@pklaptop:[~]$ npms                            
zsh: permission denied: npms
psykukumber@pklaptop:[~]$ npms search
zsh: permission denied: npms

Have this bug on yarn 0.17.8 , Node 6.9.1, Ubuntu.

$ sudo yarn global add gulp

Then as non-root user:

$ cd app; gulp
fs.js:640
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EACCES: permission denied, open '/usr/local/share/.config/yarn/global/node_modules/arr-flatten/index.js'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Object.Module._extensions..js (module.js:578:20)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/arr-diff/index.js:10:15)

Looks like #1344 was meant to fix this but only fixed the perrmissions on accessing the root package, not its dependencies. 馃槩

I do confirm the bug trying to yarn global add vue-cli and then vue init webpack myproject

The error:

fs.js:557
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: EACCES: permission denied, open '/usr/local/share/.config/yarn/global/node_modules/arr-flatten/index.js'
    at Object.fs.openSync (fs.js:557:18)
    at Object.fs.readFileSync (fs.js:467:33)
    at Object.Module._extensions..js (module.js:581:20)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.require (module.js:500:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/arr-diff/index.js:10:15)
    at Module._compile (module.js:573:32)

I'm having the same issue.
Installed yarn version 0.17.10

> forever start index.js

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

Error: EACCES: permission denied, open '/usr/local/share/.config/yarn/global/node_modules/arr-flatten/index.js'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Object.Module._extensions..js (module.js:578:20)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/arr-diff/index.js:10:15)

After the upgrade to yarn 0.18.1, I don't have this issue anymore.
Edit: looks like the upgrade might fix it, but a fresh install still breaks for me on 0.18.1

Same here when using Vagrant and installing globally.

Environment

ubuntu/trusty64: v20161214.0.0 
node: v6.9.2
yarn: v0.18.1

Error

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

Error: EACCES: permission denied, open '/usr/local/share/.config/yarn/global/node_modules/arr-flatten/index.js'
at Error (native)
at Object.fs.openSync (fs.js:640:18)
at Object.fs.readFileSync (fs.js:508:33)
at Object.Module._extensions..js (module.js:578:20)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/usr/local/share/.config/yarn/global/node_modules/arr-diff/index.js:10:15)```

Looks like I spoke too soon. The upgrade may have fixed that particular installation, but a fresh install still has this issue.

Also seeing the bug with yarn global v0.18.1. A workaround would be to manually give read access to everybody with:

sudo chmod a+r -R /usr/local/share/.config/yarn/global/

I have to say that I tried to repeat the steps in my previous comment, after upgrading to yarn 0.18.1, i.e.

yarn --version //0.18.1
yarn global add vue-cli 
vue init webpack myproject

After the upgrade the commands run without a problem (no EACCES: permission error)

thank you @PowerKiKi ,I solved it

I have tried with

yarn --version
0.19.1

The problem is still present. I have clean the cache and after fetching arr-flatten package - it's saved again with wrong permissions.

npm-array-unique also has this problem:

/home/tomcat/.cache/yarn$ ls -la * | grep "\-rwx\-\-\-\-\-\-" -B 5

npm-array-unique-0.2.1-a1d97ccafcbc2625cc70fadceb36a50c58b01a53:
total 168
drwxrwxr-x    2 tomcat tomcat   4096 Feb 13 13:21 .
drwxrwxr-x 1330 tomcat tomcat 139264 Feb 13 13:21 ..
-rwx------    1 tomcat tomcat    512 Mar 25  2015 index.js
-rwx------    1 tomcat tomcat   1088 Mar 25  2015 LICENSE
-rwx------    1 tomcat tomcat    862 Mar 25  2015 package.json
-rwx------    1 tomcat tomcat   1965 Mar 25  2015 README.md
--
npm-arr-flatten-1.0.1-e5ffe54d45e19f32f216e91eb99c8ce892bb604b:
total 168
drwxrwxr-x    2 tomcat tomcat   4096 Feb 13 13:21 .
drwxrwxr-x 1330 tomcat tomcat 139264 Feb 13 13:21 ..
-rwx------    1 tomcat tomcat    455 Mar 11  2015 index.js
-rwx------    1 tomcat tomcat   1088 Mar 11  2015 LICENSE
-rwx------    1 tomcat tomcat   1133 Mar 11  2015 package.json
-rwx------    1 tomcat tomcat   1845 Mar 11  2015 README.md

Starting from scratch with yarn 0.21.3 and still getting this error.

It seems to me that there is enough people who reported this to consider the issue "confirmed" (and thus remove the "needs confirmation")

The error still lingers in yarn 0.20.3.
I installed packages as root and got an error when running tests as a non-root.


> jest

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

Error: EACCES: permission denied, open '/code/node_modules/arr-flatten/index.js'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Object.Module._extensions..js (module.js:578:20)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/code/node_modules/arr-diff/index.js:10:15)

@soredake Please add a reference to the fix if you confirm this is solved. Otherwise, please add some explanation of closure or reopen if it was a mistake.

PLEASE. DO. SOMETHING. @bestander @soredake

Let's reopen this for now

I guess this is related with chroot?

$ yarn --version
v0.24.5

$ yarn global add yo

$ yo
/usr/local/share/.config/yarn/global/node_modules/mkdirp/index.js:90
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/root/.config'
    at Object.fs.mkdirSync (fs.js:894:18)
    at sync (/usr/local/share/.config/yarn/global/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/usr/local/share/.config/yarn/global/node_modules/mkdirp/index.js:77:24)
    at Configstore.get (/usr/local/share/.config/yarn/global/node_modules/configstore/index.js:38:13)
    at Configstore (/usr/local/share/.config/yarn/global/node_modules/configstore/index.js:27:44)
    at new Insight (/usr/local/share/.config/yarn/global/node_modules/insight/lib/index.js:37:34)
    at Object.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/yo/lib/cli.js:172:11)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

If someone can add a repro step that would help a lot.
I think the failure is related to how Yarn is installed.

@bestander I think you're right. I had the same problem. I had yarn installed through npm. I uninstalled yarn and gulp:
npm uninstall yarn gulp --global
I installed yarn using the recommended practices here (in my case apt-get): https://yarnpkg.com/lang/en/docs/install/#linux-tab (See how it mentions that installing yarn with npm is not recommended on the alternative tab.. I never knew that)

I then installed gulp 4 using yarn: sudo yarn global add gulp-cli

This issue appears to me on OSX if yarn (0.23.1) has been already installed with brew brew install yarn and install yarn 1.x with npm npm i -g yarn. I removed yarn from npm npm -g remove yarn und run brew upgrade yarn

Closing since this should be resolved in the recent versions of Yarn. Feel free to reopen with a repro script if it is still broken.

brew install yarn --without-node

This is worked for me.
I had to override the installation but it worked.

Was this page helpful?
0 / 5 - 0 ratings