Skip to content

Lack of globally installed node-gyp package causes yarn.lock file to not be created when yarn says it was #3728

Description

@jharris4

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

Bug

What is the current behavior?

Adding an the uws package 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.json file:

{
  "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"
  },
  "optionalDependencies": {
    "uws": "~0.14.4"
  }
}

Then run yarn install. It will report success Saved lockfile. but the yarn.lock file does not exist.

Removing the dependency and running the same steps (with rm -rf node_modules and rm yarn.lock first if necessary to start from a clean state) does not produce the bug:

{
  "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"
  }
}

Note that running yarn install a second time does correctly create the lock file.

This bug might have something to do with the fact that the uws package uses an install script with node-gyp: https://github.com/uNetworking/bindings/blob/master/nodejs/dist/package.json

What is the expected behavior?

The yarn.lock file 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

Activity

  1. jharris4 commented on Jun 26, 2017

    @jharris4
    Author

    Actually, just discovered that it seems to be specific to the uws package. Moving from optional dependencies to regular dependencies still causes the lock file to not be created.

  2. 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
  3. jharris4 commented on Jun 26, 2017

    @jharris4
    Author

    npm install -g node-gyp fixes the issue. It seems that with Node 7, node-gyp was bundled with Node. But with Node 8 it is not...

  4. domoritz commented on Jun 26, 2017

    @domoritz

    Can 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.

  5. jharris4 commented on Jun 28, 2017

    @jharris4
    Author

    It appears that yarn is supposed to be adding node-gyp as a dependency, but it's just not working properly:

    await globalRun(config, reporter, {}, ['add', 'node-gyp']);

  6. BYK commented on Jul 10, 2017

    @BYK
    Member

    @jharris4 hey, just tried to reproduce this with latest master and using node 8.1.3 and I got a yarn.lock file. Can you try with the latest yarn version that is 0.28.0 or may be from master and let me know if this is still happening?

  7. self-assigned this
    on Jul 10, 2017
  8. jharris4 commented on Jul 10, 2017

    @jharris4
    Author

    @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)

  9. BYK commented on Jul 10, 2017

    @BYK
    Member

    @jharris4 - I'm downloading the .tar.gz package 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?

  10. jharris4 commented on Jul 10, 2017

    @jharris4
    Author

    I used install.sh from 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 directory
    

    So looks like the bug is still not fixed in 0.28.x :-(

  11. jharris4 commented on Jul 10, 2017

    @jharris4
    Author

    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-gyp part 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 yield looks incorrect to me. In any case, the code following that yield never seems to be executed, and I think that's related to node-gyp not being properly installed...

  12. 19 remaining items

  13. kevinpelgrims commented on Jan 4, 2018

    @kevinpelgrims

    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 error
    

    Installing node-gyp globally (as mentioned in this thread) fixed it for me.

    (I think #3905 is a duplicate)

  14. flmuel commented on Jan 14, 2018

    @flmuel

    drove me crazy...

  15. nloding commented on Mar 30, 2018

    @nloding

    I haven't reviewed all related issues, but yarn also stopped writing to my package.json. Installing node-gyp globally resolved both issues - it now updates the package.json and writes the lockfile.

  16. victornoel commented on May 25, 2018

    @victornoel
    Contributor

    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-gyp
    

    Basically, 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.

  17. victornoel commented on Jun 20, 2018

    @victornoel
    Contributor

    For the record, only solution I found was to set child_concurrency in the yarn configuration to 1 (see https://yarnpkg.com/en/docs/yarnrc).

  18. victornoel commented on Jun 20, 2018

    @victornoel
    Contributor

    Scratch that, it doesn't work.

  19. victornoel commented on Jul 18, 2018

    @victornoel
    Contributor

    @BYK @arcanis is there some plans to fix those problems once and for all?

  20. nemonemi commented on Apr 13, 2022

    @nemonemi

    I am experiencing this even now, 4 years later.

    @victornoel, what was your approach to this problem past your last comment here?

  21. victornoel commented on Apr 13, 2022

    @victornoel
    Contributor

    @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_concurrency mentioned above, maybe it works now?).

  22. nemonemi commented on Apr 13, 2022

    @nemonemi
  23. victornoel commented on Apr 13, 2022

    @victornoel
  24. nemonemi commented on Apr 13, 2022

    @nemonemi
  25. stephannielsen commented on Sep 27, 2023

    @stephannielsen

    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-gyp automatically and runs every now and then into this issue. Time to move away from yarn v1. :)

    npm/cli#6554 (comment)

    Leaving a comment primarily for others running into this problem now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions