Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn does not symlink missing binaries #3421

Open
mitsuhiko opened this issue May 16, 2017 · 16 comments
Open

Yarn does not symlink missing binaries #3421

mitsuhiko opened this issue May 16, 2017 · 16 comments

Comments

@mitsuhiko
Copy link

mitsuhiko commented May 16, 2017

What is the current behavior?
When you npm install a package like sentry-cli-binary the postinstall step will download a platform specific executable and put it into the bin folder. With yarn the symlink is not generated because the file does not exist yet.

If the current behavior is a bug, please provide the steps to reproduce.
Make a dependency to sentry-cli-binary and observe that yarn does not install the symlink for the binary whereas npm does.

What is the expected behavior?
The same behavior that npm shows.

Versions tested

$ yarn --version
0.24.4
$ npm --version
4.2.0
@rally25rs
Copy link
Contributor

rally25rs commented May 17, 2017

Currently Yarn creates these bin links during it's 'link packages' step. Install and post-install scripts are not run until after this step.

It might be feasible to re-order these steps, but the 'link' step is currently more complicated that just creating the bin links, so that 'link' step would need to be split up.

Perhaps the order should be:

  • run preinstall scripts
  • resolve
  • fetch
  • link
  • run install scripts
  • create bin links
  • run postinstall scripts

I could work on refactoring this if that behavior change seems reasonable.

@bestander
Copy link
Member

Does npm run install scripts before bin links are created and post install after?
If yes then yes, it makes sense

@mrhammadasif
Copy link

+1

@rally25rs
Copy link
Contributor

rally25rs commented Oct 27, 2017

Overall issue; Yarn should run the preinstall (and maybe other?) script(s) for each dependency before it tries to create the bin links for the dependency.

Yarn does run the preinstall script for the current working project where the install in being performed before attempting to create the bin links, but the order is different for deps.

The scripts for deps are run by package-install-scripts.js and it just loops over the scripts

const INSTALL_STAGES = ['preinstall', 'install', 'postinstall'];

      for (const stage of INSTALL_STAGES) {
        const cmd = scripts[stage];
        if (cmd) {
          cmds.push([stage, cmd]);

The bin links are created as part of the overall "link" process in package-linker.js


From some testing with NPM, the order it takes is:

  1. preinstall
  2. make bin link
  3. install
  4. postinstall

Fixing this will take some code rearranging to ensure preinstall scripts are run for all deps before the bin link process in package-linker runs, then finish the install and postinstall script for all deps.

@zen0wu
Copy link

zen0wu commented Nov 21, 2017

Same issue: adding ios-deploy as dependency doesn't symlink its binary into node_modules/.bin.

While running yarn add ios-deploy TWICE would do (the first time would still miss it), not sure why this strange behavior.

@mauricedb
Copy link

mauricedb commented May 18, 2018

Same issue using node as a dependency as mentioned before.

The workaround that works for me is running yarn and then yarn --check-files. Just running yarn twice doesn't work for me using Yarn 1.6.0.

@justinmeiners
Copy link

justinmeiners commented Aug 9, 2018

I have this same issue. I want to build some native code in a preinstall step and then have the results linked to in .bin. Yarn runs the preinstall script, but only after installation, so the .bin step is missed. This works in NPM, but not Yarn.

Adding it a second time works.

@saurabh-deep
Copy link

+1 for this change

@cinderblock
Copy link

Extending @mauricedb's workaround:

Put this in your package.json scripts to make it automatic:

"postinstall": "yarn --check-files --ignore-scripts"

@aantron
Copy link

aantron commented Mar 22, 2020

This is also affecting package bisect_ppx. We are asking users to run yarn --check-files manually after install. The package installation works on npm. I wasn't able to get @cinderblock's automatic workaround workng.

$ yarn --version
1.21.1

@joelclimbsthings
Copy link

Encountering the same issue with a dependency installed from github, and the provided work-arounds using yarn --check-files don't work. Using npm install instead works just fine.

@cinderblock
Copy link

@joelclimbsthings which package? Does the package have a build step? Does it correctly mark the built files as the official package.json#files?

@joelclimbsthings
Copy link

joelclimbsthings commented Jan 4, 2021

Hey @cinderblock. The issue is with this fork of firebase-tools: https://github.com/firebase/firebase-tools/tree/v9.1.0
I believe everything is correctly configured within the package.json. And, as mentioned, it seems to work fine with npm.

@tylers-username
Copy link

tylers-username commented Mar 2, 2022

Changing "install": to "preinstall": fixed the issue for npm install but not for yarn add.

What's interesting is when testing this locally, yarn add /local/path does create the bin as expected.

Edit: I missed that this is specifically talking about the node bin. My context is that my preinstall script is creating a binary and then having bin: path/to/bin create the binary in `node_modules/.bin. Now take a look at my above comment :)

@tylers-username
Copy link

Does this mean that there is no way to link a binary using yarn if the module is building the file itself?

brombal added a commit to brombal/just-install that referenced this issue Jan 22, 2023
brombal added a commit to brombal/just-install that referenced this issue Jan 22, 2023
#3
yarnpkg/yarn#3421 (comment)
test


test


test


test


test


test


test


test


test


test


test


test


test


test


test


test
@brombal
Copy link

brombal commented Jan 22, 2023

I ran into this issue myself for a project that is meant to be a dependency that downloads a platform-specific binary (from another project on github) to the parent project, as part of the preinstall script, and yarn was not linking this binary to node_modules/.bin (npm, however, works fine).

I managed to work around it by creating a "stub" binary file (as shell script with only an informational echo), so that there is something for yarn to link; and then running the binary build script as part of the postinstall instead.

It's a little hacky (but in my case the whole repo is kind of a hack to install a 3rd party binary anyway, so it fits right in). I hope this is helpful anyone currently using other workarounds.

(P.S. This is the project, if you want to check what I did: https://github.com/brombal/just-install)

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

No branches or pull requests