-
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 install changes yarn.lock file #4379
Comments
I don't think this is a bug. I was able to reproduce the issue but the difference was
This change is just an optimization of the lockfile and doesn't change the semantics. We are planning to add a warning when the lockfile needs an update when running I have to admit that this is a bit unintuitive and we are trying to come up with a good solution to this. You can follow or contribute to the discussion on #4147. If you agree that this is not a bug and #4147 is a good place to continue the discussion, pleae close the issue :) |
@BYK thanks for your thoughtful response. After reading #4147, I'm on the fence about closing this issue. I'm hoping a bit more discussion here can help. #4147 seems to be exclusively about the case where the yarn.lock and package.json are not in sync - in fact the only time optimization is mentioned is in this comment: #4147 (comment) - and that comment touches on the issue that concerns me: yarn modifying the It seems to me that the It looks like I may have to, in the short term, add Is the intention that any invocation of yarn might modify |
@BYK I'm sorry to bother you about this because I know you are very busy - but I'm hoping to get a definitive answer on this. My workflow for distributing dependency changes to my team has devolved into this:
This seems to update the lock file properly (see #4476), and then optimize the lock file so that my team mates aren't checking in lock file changes. Is my team using yarn incorrectly? Should we be expecting the lock file to change with every |
@artlogic IMHO, your team mates should be allowed to check in lockfile changes even if they are just optimizations. I'd agree with the notion that That being said, your workflow might lead to unexpected side-effects, as you are pretty much giving up the locked-in versions. Deleting the lockfile means that yarn has to resolve all the dependencies version again, and it will try to fetch the most current version as pointed out in your If you still want to enforce that install does not touch lockfile, then you should use the
Check in lockfile, and then another dev would use:
DON'T ADD If you want to upgrade your dependencies, run:
If you want to upgrade only one dependency:
You can also just install a specific version of one dependency:
This allows for more fine-tuning and less headaches in the long run. |
@k0pernikus - thanks for your detailed response. First, I should apologize for conflating two issues - #4476 is driving some of my workflow. The fact that As for workflow, I can't imagine mine is the only team where one developer is in charge of maintaining/testing new dependencies while the other developers work on the code base. The big issue I have with what has started happened is that I would install/test new dependencies, tell everyone to run
However, it could be this is just the way yarn is intended to work, so for my team's projects we'll change all our repos to use frozen lockfile so that only One additional scenario... it seems like this could be a potential annoyance for projects with lots of contributors because potentially each time they clone and install, the lockfile might change. I certainly wouldn't want these optimizations in pull requests. Is the intention that most FOSS projects using yarn transition to a frozen lockfile as well? |
@artlogic Our team has |
@jboler - I hadn't seen that setting before. I'm going to have to take a look, but it looks like I'll be suggesting that we add that to the If someone from the yarn team can confirm that the intention is that |
@artlogic sorry for the late response. The thing is, it is expected that |
@BYK I agreed with @artlogic . This behavior is very confusing:
Our team consists of ~50 people who run |
@vkrol you should be able to check in a |
@BYK |
@vkrol my preference is |
@BYK maybe I do not understand the behavior of |
@vkrol it should not fail when the file can be optimized further but it is consistent with package.json and is consistent in itself. If not, this is a bug. There is even a test for this: yarn/__tests__/commands/install/lockfiles.js Lines 72 to 84 in 0415b07
|
@BYK I did not know about it. I will try this option, thanks! I think that this fact should be documented somewhere. |
I found some downside of the using of this flag. If yarn.lock can be optimized than the repeated invocations of this command |
@BYK Thanks for your response. For my team's projects, we're now using Here's the clearest example I can give of where this behavior causes problems:
To be clear, I have no problem with
I am advocating for option 3, but I could see option 2 being a reasonable choice as well. Thanks for your time! |
I kind of like the idea that |
@BYK why ~~~doesn't~~~ does yarn apply optimizations to edit: fix typo |
@spencer-brown: based on what I've seen, it actually does apply optimizations on install - that's what I find problematic |
Shouldn't the optimization to yarn.lock be run on yarn add? yarn.lock will be changing anyway. This is option number two in @artlogic's recent comment, right? Why doesn't the optimization occur then, so nobody else has to commit another yarn.lock change? |
@artlogic oops, typo :) - my comment should say "does"; edited. |
We use composer a lot and
In many years, we have never had to worry about ambiguous behaviour of I realise yarn fills a slightly different role, but composer has the equivalent issue of manual updates being made to |
1 similar comment
We use composer a lot and
In many years, we have never had to worry about ambiguous behaviour of I realise yarn fills a slightly different role, but composer has the equivalent issue of manual updates being made to |
hey kids, the lock file should never change on subsequent installs. it's just dumb. if you feel that the optimisation is worth touching it, just create a separate file instead that doesn't go into version control. |
As with Bundler's Gemfile.lock, the whole point of yarn.lock is that every time yarn install is run, you can guarantee deterministic results across all environments. If yarn install changes the lock file you lose that guarantee. Other commands such as yarn add or yarn update should obviously change yarn.lock but yarn install should not. Our team has run into issues where we have slightly different package versions installed in different environments which is exactly what we don't want. |
I'm inclined to think that |
@ryancastle |
I've been operating with |
I've been telling people that PRs including changes to the lock file will not be merged as the lock file is only changed when adding new or updating dependencies. This is what the install documentation states:
Is the documentation wrong as there are these optimizations that can happen stated above or is this a bug to take into account for the time being? ps. it still happens, and |
I'm current using |
@konekoya Yes, you are right that you currently MUST use
and cannot rely on the setting in the Depending on your content of your
but I would not rely on that (since it would break as soon as you have other settings in your rc-files.) See my comment and the relevant issue: #4570, esp. my conclusion. |
Thanks for clearing that up @k0pernikus. You just made my day :) |
I think @spencer-brown 's comment here is key to "fixing" this problem. I just tested for myself and running Now if As a workaround I am thinking of instructing all of our devs to delete node_modules whenever they need to update the lockfile to force the "optimization" before pushing the lockfiles to others. Or maybe they can run |
Update: You can't run prune manually, you just get this message: "The prune command isn't necessary. |
For me, the single biggest selling point for |
The lock file is presented as an exact specification of what will be installed, so that we don't have to worry about what will be installed. Use the same lock file, and you'll get the same install every time. But sometimes |
This is really unbelievable. Others have already stated it well. A lock file should not change on install. This negatively impacts commit workflows. Every developer in our team knows under what circumstances the lockfile is allowed to change. When a lockfile changes without the dependencies being updated, that causes unnecessary confusion and extra checking. This is basic package manager UX that is just broken. Please fix. |
I just got surprised by this behaviour, when moving from Node.js 13 to 14 all my I think the appropriate behaviour would be to emit a warning if optimizing the |
Closing as fixed in v2. |
I'm a bit confused about yarn. I've started using it just now. if I download a project that has a even running |
I only detected this because image builds started failing due to yarn EACCESSing upon trying to write the lockfile. I never suspected that yarn would want to modify it, so I didn't care about write permissions. |
Sharing my experience here because it might help others who stumble across this issue: I was wondering why "yarn.lock" gets updated by "yarn install" when I changed the version requirement in "package.json" from "1.3.2" to "^1.3.2". "yarn.lock" seemed to already fulfill this requirement (so I expected no changes to happen in "yarn.lock"):
But when I ran "yarn install" it was changed to:
That didn't happen because there is an update available for the package but because the dependency name—the version of it—didn't match anymore. That is why "yarn install" touched "yarn.lock". The update of the package was just a side effect so to speak. The requirements have changed and Yarn just adapts the lockfile accordingly. I changed "yarn.lock" as followed:
Now I get the version 1.3.2 when I run "yarn install"—and "yarn.lock" is not touched anymore. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When installing certain packages the yarn.lock file is changed. It seems to be package specific. In this case cordova triggers the behavior.
If the current behavior is a bug, please provide the steps to reproduce.
In an empty directory, do the following:
Notice that the yarn.lock file has changed.
What is the expected behavior?
Installing should not change the lock file if it already exists.
Please mention your node.js, yarn and operating system version.
node v6.11.3, yarn v1.0.1, Mac OS 10.11.6
The text was updated successfully, but these errors were encountered: