-
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.lock changes, even though it was just generated #7770
Comments
Another hypothesis: |
found different behaviour, but it seems like related
the only way is to remove
|
That's the same issue. As noted in the steps to reproduce, if I manually remove |
@arcanis I know you guys are busy with This issue affects any project that uses |
I understand - however I'm concerned investigating and fixing that will ask what will amount to a significant amount of time, and I'm pretty busy (I have another fix I need to do on the v1 trunk). Given that we plan to land Yarn 2 in January, and given that it features a completely revamped lockfile architecture I trust much more than the current one, I'd tend to defer the fix until then unless another contributor can take ownership 🤔 |
appreciate the response. hopefully transitioning from yarn v1 to v2 would be smooth... |
The main bump in the migration path at the moment is that PnP is required, which sometimes cause issues with packages that haven't been tested under it (we're typically quite fast at correcting those when we can work with their maintainers). As an additional safeguard we're working at this very moment on an optional plugin that will generate a node_modules folder like the v1 used to - making the transition much easier if you use one of the packages described above, at the cost of being less performant and stable than the regular PnP installs (but still more than the v1 😄). It's the main blocker for the stable release so you can expect it to be there on day one, but still - if you're interested to help us, trying out PnP and fixing potential issues in third-parties is immensely appreciated! 🙂 |
I'll try to investigate this as I find some free time (assigning to myself). |
At initial glance, I think this has something to do with the existence of the You can also reproduce this by not deleting |
Did a bit of research, and just dropping some notes: You can reproduce this issue with the very simple non-workspace
Then
at this point yarn.lock will be different. It looks like
and on the initial clean install, On subsequent yarn installs, it is omitted, hence the lockfile difference. Next step will be figuring out why... Edit Looks like my initial hunch was wrong about the However once downloaded, the actual
I suspect yarn is using the deps from the registry the first time, then the deps from the downloaded cached package.json the second. |
Great catch. Is this something I should report to npmjs support itself (as a registry bug)? |
Thinking about this a bit more, it appears the npm registry exposes Shouldn't yarn ignore these dependencies if "os" doesn't match and it got there from an "optionalDependencies" request? Or maybe I'm looking at it all reversed? Maybe for a truly cross-os deterministic lock file, yarn should resolve and lock |
This is the case. Since it could be there on other people's installs, if we don't still resolve and lock the "optional" ones, then you will get lockfile changes depending on whether the last person to run
Maybe? It'd probably be worth getting a comment from the npm team on the difference. To dig a little deeper into why this matters to yarn; When resolving the dependency tree, we check to see if a lockfile already exists, and if so, then checks to see if the exact locked version is already downloaded and extracted in the yarn cache. If it is already cached, we use the If the version desired is not in the cache or if the lockfile doesn't exist (or is believed to be invalid or out of date) then we get the package metadata from the registry and use that to get the sub dependencies. This unfortunately means there are 2 possible sources of truth for the sub dependencies of a package. Picking either one and using only it would cause some issues for yarn; If you only rely on the registry metadata and ignore package.json, then you always need to check the registry; we don't currently cache that metadata, so we don't have it stored locally, so this would break "offline" installs which was one of yarn's original core features. If you rely only on package.json, then you always have to download a package, extract the .tgz, and load and parse package.json to determine the next level of dependencies. This would probably negatively affect performance (although we usually end up downloading them eventually anyway, unless they get eliminated due to being "optional" and not matching the node version or OS) One possible solution would be to start caching the metadata responses from the registry locally too, along with the package .tgz file. But any way you slice it; which source of truth is "correct?" and why are they reportedly different? It would also be a fairly big change to yarn to alter the way that this works, and with yarn2 on the horizon, I'm not sure if a change of this magnitude would be worth it. I'd be interested to see if it is "normal" for the npm registry to report dependencies differently than the library's package.json, or if this is a rare oddity. If you do open an npm issue, please link it here. |
The forum in https://npm.community is in read-only mode, so I believe they can only be contacted by support e-mails (via https://www.npmjs.com/support). The thing is, even with yarn getting the responses it gets from the registry, it should still be able to see npm seemingly fixed it in v5.6: https://blog.npmjs.org/post/167963735925/v560-2017-11-27 |
related to #5998? |
I opened a question against npm/cli (see linked issue above), but judging from the
I'm guessing they actually cache the registry metadata responses too (which yarn does not, we use the package.json inside the cached library instead) and use that when rebuilding the dependency tree, which would explain why npm doesn't exhibit this same lockfile change issue. I'm thinking the "correct" solution here would be to mimic that behavior and start caching the registry metadata responses, instead of relying on the library's pacakge.json to match, but I really don't like that the npm registry seems to override what a package publisher puts in their package.json as the source of truth for dependencies. I think that could cause other issues, like if you were to clone I guess let's see if there is any comment on the npm issue that I opened... |
Any news on this? |
For now, we've added {
"resolutions": {
"chokidar": "^3.3.1"
}
} We noticed that all of our dependencies that depend on |
Reasons explained here: yarnpkg/yarn#7770 (comment) Tl;dr: * fresh run of `yarn` (without yarn.lock) resolves dependencies from npm registry * following runs of `yarn` resolve dependencies from local package.json files * the fsevents packages declares node-pre-gyp dep as optional but the fact that the dependency is optional is not reflected on npm's registry...
Most likely fixed in v2 |
@arcanis this started happening fairly recently. I'm not sure if this is a regression due to 1.21.1, or the new fsevents release (or something else entirely).
Do you want to request a feature or report a bug?
Bug. Probably affecting many out there.
What is the current behavior?
yarn
changesyarn.lock
after a secondary run.If the current behavior is a bug, please provide the steps to reproduce.
https://github.com/wixplosives/sample-monorepo
What is the expected behavior?
A fresh install of yarn should generate a "final" lock file. Running yarn on the generated
yarn.lock
should not change it unless a version request was changed (someone modifiedpackage.json
since lock file generation).Please mention your node.js, yarn and operating system version.
yarn 1.21.1
node 12.13.1
fedora 31
Observations
fsevents
released a new node12 compatible version (v1.2.11). yarn picks that version up. it's an optional dependency of chokidar. older versions of fsevents had node-pre-gyp as a dependency, and that seems to be the major change in the lock file. not sure if it's related, but perhaps you'll know more. Should be noted that fsevents does not end up installed (optional dep) on non-darwin machines, such as my linux machine.The text was updated successfully, but these errors were encountered: