yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.42k stars 2.72k forks source link

yarn install fails if npm isn't installed #4097

Open Jehops opened 7 years ago

Jehops commented 7 years ago

This is a bug report for an issue installing node modules for Mastodon on FreeBSD 11.1 with node 6.11.1 and yarn 0.27.5 installed. Here are the package.json (small patch relative to upstream) and yarn.lock files. Doing yarn install is successful if npm is installed, but if npm is not installed, this error occurs. yarn install does not install anything outside of the Mastodon project directory when npm is installed.

success Installed "node-gyp@3.6.2" with binaries:
      - node-gyp
verbose 31.879 Error: /usr/local/www/mastodon/node_modules/uws: Failed to auto-install node-gyp. Please run "yarn global add node-gyp" manually. Error: "We don't have permissions to touch the file \"/usr/local/bin/mkdirp\"."
    at MessageError (/usr/local/lib/node_modules/yarn/lib/yarn-cli.js:138:5)
    at /usr/local/lib/node_modules/yarn/lib/yarn-cli.js:34736:13
    at throw (native)
    at step (/usr/local/lib/node_modules/yarn/lib/yarn-cli.js:91:30)
    at /usr/local/lib/node_modules/yarn/lib/yarn-cli.js:104:13
error /usr/local/www/mastodon/node_modules/uws: Failed to auto-install node-gyp. Please run "yarn global add node-gyp" manually. Error: "We don't have permissions to touch the file \"/usr/local/bin/mkdirp\"."
Daniel15 commented 7 years ago

The error message explains what's wrong:

Failed to auto-install node-gyp. Please run "yarn global add node-gyp" manually. Error: "We don't have permissions to touch the file \"/usr/local/bin/mkdirp\"."

Some packages are missing a dependency on node-gyp even though they require it. They implicitly rely on npm installing it globally for you. When you try to install one of these packages with Yarn, it first tries to use npm's version of node-gyp. If that fails, Yarn tries to install node-gyp itself. However, this is failing because it's trying to install into /usr/local for some reason.

There's two potential fixes here:

  1. Run yarn global add node-gyp yourself
  2. Update whatever native package is failing (looks like uws) to include node-gyp in its dependencies
Jehops commented 7 years ago

Thanks for your quick response.

Fix 1. is a problem for those who don't have root access on the system. It looks like fix 2. is not going to happen.

Daniel15 commented 7 years ago

Fix 1. is a problem for those who don't have root access on the system.

Hmm, Yarn shouldn't be trying to use /usr/local if you don't have root access. We haven't done any testing on FreeBSD though, so maybe there's some platform-specific issues here.

Jehops commented 7 years ago

Maybe it could also have something to do with the FreeBSD yarn package, which, by default, gets installed under /usr/local. The package is quite small, containing these files and the only local patch is to set installationMethod to pkg in package.json.

I am willing to test anything that you think would be helpful for getting this working. Just let me know.