Repository navigation
Lack of globally installed node-gyp package causes yarn.lock file to not be created when yarn says it was #3728
Description
Activity
Actually, just discovered that it seems to be specific to the
uwspackage. Moving from optional dependencies to regular dependencies still causes the lock file to not be created.- changed the title
[-]Adding optionalDependencies causes yarn.lock file to not be created when yarn says it was[/-][+]Adding uws package as a dependency causes yarn.lock file to not be created when yarn says it was[/+]on Jun 26, 2017 npm install -g node-gypfixes the issue. It seems that with Node 7, node-gyp was bundled with Node. But with Node 8 it is not...Reacted by René van Mil, Karl Horky, Noorzaini Ilhami, Alexandre Silva, seanohollaren and pattanaponny002Can confirm. This fixes the issue for me.
The fix for this in yarn should be to add this dependency and also actually check whether the lockfile was created instead of just printing a message.
It appears that yarn is supposed to be adding
node-gypas a dependency, but it's just not working properly:yarn/src/util/execute-lifecycle-script.js
Line 245 in 23dd84b
await globalRun(config, reporter, {}, ['add', 'node-gyp']); @jharris4 hey, just tried to reproduce this with latest master and using node 8.1.3 and I got a
yarn.lockfile. Can you try with the latestyarnversion that is0.28.0or may be from master and let me know if this is still happening?@BYK I just checked and the issue is still there with node 8.1.3 and yarn 0.27.5.
I'm using homebrew to install yarn, can you suggest some steps to test out yarn 0.28.x? (it doesn't seem to be published on npm, and the nightlies page doesn't list the tarball either)
@jharris4 - I'm downloading the
.tar.gzpackage from Node's site for Node 8 and then use my local repo for yarn:git clone git@github.com:yarnpkg/yarn.git cd yarn yarn; yarn build; alias yarn="/path/to/node8 /path/to/yarn/bin/yarn.js"Then follow your repro steps. May be this is related to Homebrew?
I used
install.shfrom the nightlies build, and then copied over the latest tarball contents into~/.yarn/Here's the output:
$ yarn --version 0.28.0-20170710.0902 $ ls yarn.lock ls: yarn.lock: No such file or directory $ ls node_modules ls: node_modules: No such file or directory $ cat package.json { "name": "yarn-lock-bug", "version": "1.0.0", "description": "repro bug with yarn not creating lock file", "author": "jharris4", "license": "MIT", "dependencies": { "engine.io-parser": "~2.1.0", "uws": "~8.14.0" } } $ yarn install yarn install v0.28.0-20170710.0902 info No lockfile found. [1/4] 🔍 Resolving packages... warning engine.io-parser > has-binary2 > isarray@2.0.1: Just use Array.isArray directly [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... [4/4] 📃 Building fresh packages... ⠁ ⠁ ⠁ ⠁ info This package requires node-gyp, which is not currently installed. Yarn will attempt to automatically install it. If this f[1/1] ⠁ uws [1/1] ⠄ uws [1/1] ⠠ uws [-/1] ⠠ waiting... [-/1] ⠠ waiting... [-/1] ⠠ waiting... success Saved lockfile. ✨ Done in 2.04s. $ ls yarn.lock ls: yarn.lock: No such file or directorySo looks like the bug is still not fixed in 0.28.x :-(
I tried digging a little further into the issue. I'm a bit of a noob with await/generator syntax, but something seems to be going wrong with the
add node-gyppart of the code.It gets to this line:
const res = await command(config, reporter, flags, args); In the source that line is:
const res = await command(config, reporter, flags, args);But in the distributed/transpiled source it is
const res = yield command(config, reporter, flags, args);I could be mistaken, but that
yieldlooks incorrect to me. In any case, the code following thatyieldnever seems to be executed, and I think that's related tonode-gypnot being properly installed...19 remaining items
I can confirm that this is still an issue with Node v9.3.0 and Yarn 1.3.2
warning Error running install script for optional dependency: "/[...]/node_modules/fsevents: Cannot read property 'config' of undefined" info This module is OPTIONAL, you can safely ignore this errorInstalling
node-gypglobally (as mentioned in this thread) fixed it for me.(I think #3905 is a duplicate)
Reacted by Davedrove me crazy...
I haven't reviewed all related issues, but yarn also stopped writing to my package.json. Installing
node-gypglobally resolved both issues - it now updates the package.json and writes the lockfile.Still having problem with node-gyp during yarn install but not always, mainly happening in CI:
[INFO] [4/4] Building fresh packages... [INFO] info This package requires node-gyp, which is not currently installed. Yarn will attempt to automatically install it. If this fails, you can run "yarn global add node-gyp" to manually install it. [ERROR] error An unexpected error occurred: "/builds/frontend/node_modules/node-sass: Cannot read property 'getOption' of undefined". [INFO] info If you think this is a bug, please open a bug report with the information provided in "/usr/local/share/.config/yarn/global/yarn-error.log". [INFO] info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. [INFO] [1/4] Resolving packages... [INFO] [2/4] Fetching packages... [INFO] [3/4] Linking dependencies... [INFO] [4/4] Building fresh packages... [INFO] success Installed "node-gyp@3.6.2" with binaries: [INFO] - node-gypBasically, it feel like there is some kind of concurrency issue: node-gyp is installed because it is needed, and sometimes (not always…) it's not ready yet for installing the dependency that initially required it.
Reacted by Michael Cornel and Patrick KooijmanFor the record, only solution I found was to setchild_concurrencyin the yarn configuration to 1 (see https://yarnpkg.com/en/docs/yarnrc).Scratch that, it doesn't work.
I am experiencing this even now, 4 years later.
@victornoel, what was your approach to this problem past your last comment here?
@nemonemi sorry, this was a long time ago and I don't use yarn much lately, but I remember this was related to installing multiple package at the same time, so I would look into concurrency related options (such as
child_concurrencymentioned above, maybe it works now?).6 years later, NPM removes the node-gyp binary from its bundle with v9.7.2 which is released with Node 18.18. Breaking our builds because now yarn tries to install
node-gypautomatically and runs every now and then into this issue. Time to move away from yarn v1. :)Leaving a comment primarily for others running into this problem now.
Reacted by Karl Horky, Shiaupiau, Common, Brooce, Luis Custodio, Joe Fleming, Wynand Boshoff, Douglas Alves, Samuel Čavoj, Cat Chen and 19 more
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Adding an the
uwspackage to a package.json dependencies section causes yarn to report that it created the lock file successfully, but the lock file does not exist.If the current behavior is a bug, please provide the steps to reproduce.
Create an empty folder with the following
package.jsonfile:Then run
yarn install. It will reportsuccess Saved lockfile.but the yarn.lock file does not exist.Removing the dependency and running the same steps (with
rm -rf node_modulesandrm yarn.lockfirst if necessary to start from a clean state) does not produce the bug:Note that running
yarn installa second time does correctly create the lock file.This bug might have something to do with the fact that the
uwspackage uses an install script withnode-gyp: https://github.com/uNetworking/bindings/blob/master/nodejs/dist/package.jsonWhat is the expected behavior?
The
yarn.lockfile should always be created when the yarn cli reports that it was.Please mention your node.js, yarn and operating system version.
MacOS 10.12.5
Node 8.1.2
Yarn 0.24.6