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 doesn't create simlink to node binary #6583
Comments
This is caused by 6601f4b cc @connectdotz, can you take a look please? It sounds like |
@arcanis how do you symlink a target if it doesnt exist? The subsequent It looks like the |
Symlinks can point to non-existing destinations,
No, packages need to be linked against their dependencies before being built (take the example of a package that uses babel to compile itself: it needs to be able to access its babel dependency, meaning that the link must happen before the build). |
from the diff of 6601f4b you can see the original logic is always to skip symlink when target doesn't exist, defaulting if I comment out the
given
but when should the dependencies kick off their builds? shouldn't they be built before the root package can link against them? In other words, I expect the following sequence:
instead we have:
|
It seems like this
Not sure, I don't see why it worked before 😐 Maybe the
No - linking (in Javascript, at least) is a step that doesn't require the packages to be built. It's not "linked" in the same sense as in C/C++, where all object files need to be built to then be merged into the final executable. |
when I said
Only after that the
I am not sure what the right fix is here if we don't execute |
Why that? What issue do you think it might cause? |
Note that I don't suggest commenting the |
exactly the problem 82b77a5 tried to fix, we don't want the node_module/.bin end up with bunch of "dead" symlinks that point to nowhere! "linking to a non-existing target" violates the basic data/logic integrity. How do we know they will be created later? It seems at best a hack, and worse we didn't address the real issue here that might manifest to other problems: from npm-scripts
yarn didn't honor it... when the root package tried to symlink to the node package, the node package's |
Sure we do. If the package tells us there's a bin entry, then we should assume it knows what it is doing, Even if the target doesn't exist it might still exist later (it might be created at runtime for all we know).
Because the package tells us so. Not creating the symlink actually breaks the contract we make with the package, since it explicitely tells us to create a link to a binary but we refuse to do so.
We don't, but that's the point: we shouldn't make any assumption in the first place.
That doesn't have any sense, like most of the npm documentation. What does it mean for a package to be "installed"? Are they all executed as very first step, before anything is copied from the cache? Before it is copied to the node_modules? Before it is built? Can a package preinstall script be run after the postinstall from another one? As always we're left to reverse engineer the thing ... |
the node package also explicitly tell us to preinstall the node binary but we refuse to do! Just imagine if we have done that, the symlink will be correctly created and there would be no need to justify "why linking with a non-existing binary is actually a good thing..." I searched around the issues and found that this is not a new issue, it has been mentioned quite a few times (see #3421 and related). While allowing linking to non-existing file could close this issue, so is running
Based on @rally25rs diagnosis, it seems the lifecycle execution is "horizontal", i.e. all preinstall got executed first, then linking, then all postinstall. I would love to see the lifecycle issue got resolved, if you guys are interested in addressing it and need some help, just let me know, I might be able to find some cycle. |
Has there been any update on this? Is there any life cycle script that we can use for our packages that is called before the symlink is created but after the dependencies are installed? |
What is the current behavior?
If the
node
package is installed as a dependency to the current package, Yarn does not link to the node binary in node_modules/.bin directory. But npm does.Steps to reproduce:
yarn init -y
yarn add node@10.5.0 --exact
"scripts": { "v": "node -v" },
to thepackage.json
yarn v
I expect it to report v10.5.0 (the one I set in step 2). But it reports the one I have installed on my machine.ls node_modules/.bin
shows 0 files in the directory.rm -r node_modules
npm i
yarn v
reports v10.5.0 as expected.ls node_modules/.bin
shows the symlinked node binary in the directory.What is the expected behavior?
I expect that yarn creates a symlink to the node binary in the node_modules/.bin directory for the
node
package as well. Please note that this works for other packages, e.g. webpack but not for node.Here is an article (not written by me) about why I expect this behavior: https://nitayneeman.com/posts/standardizing-node.js-version-in-an-npm-package/
Please mention your node.js, yarn and operating system version.
The text was updated successfully, but these errors were encountered: