Code Monkey home page Code Monkey logo

Comments (5)

jeffesquivels avatar jeffesquivels commented on June 11, 2024

Hi again,

I did some more digging on this issue and it seems the problem started with npm/cli@3a7378d that removed node-gyp from npm's bin/ directory (where yarn looks for it when it is not present locally) which eventually made it into Node v20.0.40 via nodejs/node@350fecb.

Now, 94db31e fixed this issue for packages that depends on node-gyp directly (as that local version will be used) but it will still fail for the case where the global node-gyp needs to be used.

A quick and easy solution/workaround would be to use npm exec to execute the global node-gyp installation (which would make sure that the right path is used by yarn, which doesn't happen when invoking it directly) as can be seen here jeffesquivels@f8977d3 (I tested this with both npm and yarn, both on Linux and Windows for Node v20.5.1), but I'm not sure if the maintainers would prefer a different approach to solve this (or if this is considered not an issue).

Thanks!

from node-gyp-build.

mafintosh avatar mafintosh commented on June 11, 2024

Sounds good to me. That works on all later npm versions?

from node-gyp-build.

vweevers avatar vweevers commented on June 11, 2024

where yarn looks for it when it is not present locally

So isn't the real bug that yarn can't find node-gyp anymore? It's a bit strange to use npm to fix a bug in yarn, which is supposed to be a (complete) alternative to npm.

from node-gyp-build.

jeffesquivels avatar jeffesquivels commented on June 11, 2024

Sounds good to me. That works on all later npm versions?

I just tested it with the following combinations of node and npm:

  • For Node v16.20.2: npm versions 9.6.7 and 9.8.1.
  • For Node v18.17.1: npm versions 9.67 and 9.8.1.
  • For Node v20.5.1: npm versions 9.8.0 and 9.8.1.

Which is basically the npm version that came bundled with the official docker image of each major version of Node that is still supported, plus the latest npm version (upgrading via npm i npm -g).

I don't know if there's any other combinations of versions that I'm missing and that are also relevant.

from node-gyp-build.

jeffesquivels avatar jeffesquivels commented on June 11, 2024

So isn't the real bug that yarn can't find node-gyp anymore?

Yes, that is the real bug indeed and the ideal solution would be to fix it there, but yarn v1 is no longer maintained even though, unfortunately, it's still bundled with most common distribution methods for Node[0][1].

There is one argument in favor of fixing it here, though: when a package is not using node-gyp-build, yarn will detect if the package requires node-gyp and will install if it is not explicitly listed as a dependency which allows the installation to finish successfully. One could argue that node-gyp-build is kind of breaking this logic.

But I guess one could also argue that the proper fix then would be to somehow prevent yarn's logic from breaking (although I have the feeling that that would require a much bigger code change here).

It's a bit strange to use npm to fix a bug in yarn, which is supposed to be a (complete) alternative to npm.

Yes, it's also a bit ironic too 😄.

I'm also happy to implement a different solution if we can come up with one that makes sense to everybody.

[0] For example, this is the latest official docker container for Node v20:

$ docker run -it --rm node:20 /bin/bash
root@f3b700aa176b:/# yarn --version
1.22.19

[1] And this is an installation of yarn using the latest Node LTS:

root@ubuntu-s-2vcpu-4gb-amd-sfo3-01:~# nvm i --lts
Installing latest LTS version.
Downloading and installing node v18.17.1...
Downloading https://nodejs.org/dist/v18.17.1/node-v18.17.1-linux-x64.tar.xz...
####################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.17.1 (npm v9.6.7)
Creating default alias: default -> lts/* (-> v18.17.1)
root@ubuntu-s-2vcpu-4gb-amd-sfo3-01:~# npm i yarn -g

added 1 package in 951ms
npm notice 
npm notice New minor version of npm available! 9.6.7 -> 9.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.8.1
npm notice Run npm install -g [email protected] to update!
npm notice 
root@ubuntu-s-2vcpu-4gb-amd-sfo3-01:~# yarn --version
1.22.19

from node-gyp-build.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.