-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 overwrites symlinked dependencies #3288
Comments
I'm also experiencing this. For the second time this week I lost data in 8 or 9 different projects that were symlinked (not to one another, just symlinked globally). Unfortunately, I didn't know it was yarn that caused the data to be lost the first time. I assumed it was the tool I use for git. |
there will be version mismatches and strange commits on a number of repos over the next few days. yarn completely destroyed data in 8 or 9 projects and reverted them to an earlier state. see yarnpkg/yarn#3288
Help investigating this is welcome. |
@bestander Awesome. Thanks a lot. I'll get to it :) |
|
To clarify,
In case it is not clear, it seems to me like the entry in the screenshot above will result in |
This is a response to #1214 (comment), as it seems like it belongs on this issue.
Before we go too far down the debugging path... can we get some clarification on whether or not this is actually a bug? Because it sure smells like a design decision at the moment. In particular:
|
I'm primarily interested in finding out why this happens for some projects and not others. I have 40 projects in my tree, all depending on each other in some way, but only some projects are affected by this behavior. To me that indicates that it is a bug, as it should either always preserve the symlinked modules or it should never do it. It is my understanding that preserving the projects is the intended behavior and it is also my opinion that this is the right choice. btw, I'm currently assuming that circular dependencies are what's causing this for us, but I was running out of time for today to investigate this assumption. |
Sorry, allow me to clarify my point and the reason for the questions. If you're saying that it's a bug when yarn overwrites user's project files, yes, that would be an understatement. I don't think there is any confusion about that part. A couple of points of clarification, as it relates to my own experience with this bug:
IMO, there is no circumstance in which it would be okay for yarn to delete or create any file or project folder (outside of What I think is happening is this - which might be totally wrong, but I can't debug this at the moment, so I'll take a stab in case it helps:
Which brings me back to my questions and the reason for asking them. I might be wildly wrong in my assertions above, but it seems to fit exactly what's happening. And if it is, I'm having a hard time understanding why yarn would do anything at all with symlinked files. There would be no performance advantage, and there is zero chance of being able to guarantee a deterministic installation with symlinked files, etc. |
In case it wasn't clear, I was hoping for some support from someone with better knowledge of how yarn should work. But, apparently, nobody does know, which is why we have the issue in the first place. Very disappointing community. |
why was this closed?!??! this problem is not solved, I'm also participating in this issue. @bestander can you please reopen this issue? |
@jonschlinkert, your contribution is welcome, thanks for speaking up. |
Yeah, your contribution is welcome, but don't expect any help. |
We are also affected by this. Would love to contribute or help on the issue but need guidance as to where this functionality is found. I'll be browsing the source code either way. |
Welcome, @josebalius! |
I can confirm this issue and can hopefully provide additional details. I'm running yarn v0.24.5 and node v6.9.5 I have two repos I'm working on:
Now, I want to upgrade
What this seems to do is copy This is basically what's described in the previous comments, but to make things even more interesting, if I:
It still overwrites the I think this is what you referenced, @jonschlinkert, with this:
So I can confirm that, as well For now, the work around we've settled on is:
|
I just lost some work through this, and since I rely on symlinking to work on a multi-module system it's starting to make me fear running yarn at all. Any chance it can get some more attention? |
Very frustrating issue! Would massively appreciate a fix for this - it's pretty debilitating when trying to work with linked modules. |
The issue is somewhere in package-linker.js, there are repro steps. |
This is back in 1.2.0. Repro steps: $ rm -rf node_modules dupe here: #4603 |
I've tried to create a proof of concept repro script: It will create a temporary mock package, link it, then write a package.json to the current dir with a dep to Next it bumps the version of My question to participants of this thread is whether this is in fact the proper repro causing the problem in this ticket. The problem can have different parameters that are subtle though important to the problem so that's why I'm asking. On a side note; how does this lose data? I can understand certain cases in which this causes problems but for as far as yarn is concerned it only seems to destroy the symlink, not the actual files. Is it because the link was shadowing a package that's also in the package.json which then gets overridden? That'd be an example of a subtle difference that's important. Here is a version where the linked package shadows a package in the |
Note that at 1.2.0 the behavior is that the symlinked dir is replaced in both cases of the test script above. |
@qfox does that mean is replacing the symlinks by design? |
I found where the issue is, and what the problem is but I'm not sure how to solve it. @bestander was right is in package-linker.js. On line Problem: On line 302: it loops through linkedModules and fills linkTargets with the name and path of each one. The listing of the .config directory is: $ ls -l /Users/gandazgul/.config/yarn/link/pkg While the listing of ./node_modules is: As you can see |
Ok. I resolved it by using fs.realpath instead of readlink which returns the entire path of the symlink. If both are the same then this is a yarn linked module and should not be removed. I tested locally with my repro scenario both installing and upgrading. I'll submit a PR. |
I can't seem to write a test that will break with this issue. I have the issue fixed but would love some help with the unit test. The test runs fine but doesn't trigger the error condition. Both paths are identical when run through the test but obviously not when run in a more real world scenario. Here is the PR: #4757. Help is appreciated. |
@gandazgul, I love it how you debugged the code, thanks a lot for contributing! |
@bestander :) thanks. |
I don't know :) That was before my time.
Awesome! |
@gandazgul I'm using your branch on my local for now, thank you :) 💯 |
**Summary** Actual fix: changed fs.readlink to fs.realpath when checking if a symlink is a linked dependency in package-linker.js This fixes yarn removing linked deps when installing or updating. Fixes #3288, fixes #4770, fixes #4635, fixes #4603. Potential fix for #3202. **Test plan** See #3288 (comment) for repro steps. See #3288 (comment) for my explanation of the problem. With a real world test scenario this works, but I'm unable to have it break from a unit test. I added a test in the integration suite but with the bug added back in it still passes because both generated paths are identical. I would like some help with the unit test.
…#4757) **Summary** Actual fix: changed fs.readlink to fs.realpath when checking if a symlink is a linked dependency in package-linker.js This fixes yarn removing linked deps when installing or updating. Fixes yarnpkg#3288, fixes yarnpkg#4770, fixes yarnpkg#4635, fixes yarnpkg#4603. Potential fix for yarnpkg#3202. **Test plan** See yarnpkg#3288 (comment) for repro steps. See yarnpkg#3288 (comment) for my explanation of the problem. With a real world test scenario this works, but I'm unable to have it break from a unit test. I added a test in the integration suite but with the bug added back in it still passes because both generated paths are identical. I would like some help with the unit test.
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I have a development checkout of the package
@company/foo
which I made globally available throughyarn link
. I then linked that packages into my project@company/project
.I also have package
@company/bar
, which is linked identically into@company/project
.When I now run
yarn upgrade @company/bar
in the directory of@company/project
, yarn will overwrite my local development checkout with data it pulled from the npm registry.If the current behavior is a bug, please provide the steps to reproduce.
It should be reproducible with any combination of linked packages as outlined above. It seems to me that when yarn says "linking dependencies", it will simply pull some fixed version from the local cache and overwrite my local development snapshot.
What is the expected behavior?
The linked package is not overwritten. npm deals with this: npm/npm@1619871
Please mention your node.js, yarn and operating system version.
6.10.2, 0.23.3, Windows 10
The text was updated successfully, but these errors were encountered: