Open zamotany opened 4 years ago
In my case, it might be the version confilcts of @babel/core
. I solved it by: check out the version installed by yarn why @babel/core
, add resolution to the package which is not the the same version to unify the version.
Adding this incase someone else (god help them) has a similar issue as I've just spent half my weekend debugging / basically reformatting my computer...
I setyarn policies set-version 1.19.1
thinking everything was fine. A few hours later I did a build of my Next.js app and was getting this Error occurred prerendering page...
. I literally tried everything under the sun, and have just realised that doing yarn policies set-version 1.19.1
was the cause.
What's even stranger is it destroys my local project. If I switch to a stable branch, delete all the node modules, yarn.lock etc etc, switch back to the latest version yarn, and run yarn install
, then build my Next.js app again, I get the same error.
I've no idea what's going on tbh. I literally re-installed node, yarn etc. The only solution was to delete the app and clone it again.
I had the same issue with eslint
package. Turns out the problem was my workspace root had eslint as a dev dependency, but I also had a workspace package that depended on an npm package that depended on a different version of eslint, which I assume ended up breaking the hoisting process somehow. All I did was make sure all packages depended on the same version of eslint and the error went away.
also experiencing this issue. @export-mike 's solution works as a hotfix, thank you
Is there any official response/fix roadmap from yarn dev team about this?
My solution was to switch to pnpm. Highly recommend it!
I'm 99% sure this is the same issue as #7734 – can we please close this as a duplicate?
I'm 99% sure this is the same issue as #7734 – can we please close this as a duplicate?
I would prefer if we could keep it open. It has some valuable information about how to reproduce. The other issue feels more like a "i have the same issue" and "downgrading worked for me" kind of thread in comparison.
Linking the two and possibly getting similar issues under a common label would help but closing this isn't going to revive the discussion on the other one.
agree @customcommander and FWIW, this issue is the one that google continues to bring up when googling the error since I literally run into this problem every other day 😂
I am working in many workspaces and this issue has for some reason, become more prevalent lately.
node:v14.15.0 yarn:1.22.10
I also encountered this problem, and my solution was to delete the yarn.lock
file and re-execute the yarn install
command, and the problem was solved
ps: I had this problem after upgrading my MAC system to Big Sur
This method is not recommended because reinstalling Packages can change the current running environment and cause unpredictable problems
node:v14.15.0 yarn:1.22.10
I also encountered this problem, and my solution was to delete the
yarn.lock
file and re-execute theyarn install
command, and the problem was solvedps: I had this problem after upgrading my MAC system to Big Sur
Deleting your yarn.lock
isn't a valid solution, you should never delete your yarn.lock
without knowing exactly what you're doing. I learned this one the hard way.
To extend @jamesdbruner warning, deleting your yarn.lock
file will cause yarn to update all your packages. If dependency versions where not locked down, then every time the dependencies are installed through yarn install, the fetched dependencies may be different. If one of the dependencies has a new version available and the available version is within the specified version range in the package.json, then the newest dependency will be installed. This could be very dangerous, mostly if your version range in the package.json allows major update (because this updates can have public API changes), but sometimes you can find a new bug when updating minor versions too. The nature of yarn.lock
is to have complete control over which version of a dependency is used to have a stable enviroment for development.
a slightly simpler workaround: directly add your dependency to package.json and then run yarn
in the project root.
worked for me, yarn 1.22.4 on monorepo/lerna
Any updates or progress on investigating this? Using yarn policies set-version
to rollback/specify a different version does not fix the issue for us. Only workaround currently is to add packages to package.json by hand prior to install.
Hi, unfortunately we encountered the same issue after upgrading to a newer babel version and adding one or two additional eslint plugins. The package that is doing a violation is already added in the package.json on the root level.
As workaround I downgraded to v1.18.0. We used before 1.22.10 and also 1.19.2 had the same issue (see screenshot)
Hi, unfortunately we encountered the same issue after upgrading to a newer babel version and adding one or two additional eslint plugins. The package that is doing a violation is already added in the package.json on the root level.
As workaround I downgraded to v1.18.0. We used before 1.22.10 and also 1.19.2 had the same issue (see screenshot)
@MKruschke This bug can be fixed, without downgrading to v1.18.0, if you add the following to your package.json
"resolutions": {
"**/@babel/traverse": "PLACE_YOUR_BABEL_TRAVERSE_VERSION_HERE"
},
I just had the same problem on a monorepo Lerna + Yarn (v1.22). Solved re-creating the
yarn.lock
.
THANKS! Delete root yarn.lock!
deleting yarn.lock helped to solve this for me.
Just an FYI to anyone who hits this problem and is on yarn > 1.18
and it happens after running yarn upgrade
,
this is how you fix the issue without destroying your entire monorepo:
yarn.lock
!!
This will likely cause a cascade of compatibility issues for you app (issues scale exponentially based on the number of dependancies you have and how large/old your app is).git stash
or what ever code versioning you use if you have other changes beside the yarn upgrade
. Your yarn.lock
is corrupted beyond repair at this point.yarn upgrade
. - This restores the yarn.lock
that is correct and still works.node
environment. I use nvm
, so I just bumped up to the newest LTS release. You don't have to do this, but if you're paranoid, it doesn't hurt.yarn > 1.18
and install yarn 1.18
globally. For some reason, just setting the yarn policy
for the monorepo may not work (caused by certain operations using the global version, not the local policy version - I don't know which ones, but there's no margin for error when you are in this situation as you will have to start again if the wrong version of yarn
runs even once during the upgrade operation).
If you reset your node
environment like me, you can just run npm i -g yarn@1.18
.yarn policies set-version 1.18.0
. We did this to ensure all developers are running 1.18
minimizing the chance of the lock file corrupting.yarn upgrade
operations. Remember that if you upgrade the version of a dependency in one workspace, YOU MUST upgrade the dependency version in all workspaces, if you want to go back to a new version of yarn
after upgrading.
Even if you do not go back to a newer version of yarn
this is still recommended to prevent mismatched dependency versions from running. We suspect that yarn workspaces
is not resolving dependency trees correctly when different top level dependencies are specified across workspaces.yarn
if you need to.git stash
, but reject all yarn.lock
and package.json
changes in your stash as those are corrupted.Anyone who is currently running lerna
and yarn workspaces
should roll back to yarn 1.18
when performing upgrades just as a precaution. This issue seems to appear when you have multiple large projects in a single monorepo that share the same "complex" dependencies (with at least 2+ levels of dependencies below). When upgrading the dependencies in a single project, if the new version of the dependency has a new sub-dependency, yarn >= 1.19
does not resolve the new dependency tree correctly. Yarn's workspace checker appears to expects that all occurrences of the dependency throughout the monorepo to have the new sub-dependency, even though the other projects are using an older version that does not require it - at which point yarn
breaks and refuses to perform any new upgrades.
Upgrading all instances of the dependency to the same new version using yarn 1.18
allows the yarn.lock
file to be structured correctly. Then after the upgrade, you can switch back to the newest version of yarn and everything should work fine.
For larger teams, I recommend performing the upgrades in a container (e.g. docker
.) This ensures the environments are clean and the yarn.lock
files resolve and generate correctly, without having to alter your local environment.
Does yarn team acknowledge this as a bug? Or we are doom to use older yarn version in our repos?
I think the guidance from the yarn team is to move to yarn 2.
Not sure if it is a bug present in yarn@2
, but we're testing yarn@2
next week under the same conditions to see if the same error crops up.
If anyone else has encountered this error, try upgrading to yarn@2
. It would be useful to have more than 1 datapoint.
Also note that you have to revert back to yarn@1.22
before you can upgrade to yarn@2
. yarn@1.18
does not have the yarn set
command needed to upgrade using the defined migration instructions
Cheers, Bryan
If you're one of the many who are impacted by this issue, don't get your hopes up for a bugfix – Yarn 1 appears to have been quietly deprecated, and the maintainers no longer appear to be reviewing pull-requests in this repository.
If Yarn 2 doesn't work for you, consider switching to npm or pnpm.
FWIW I've slowly come to understand this bug more. It's very much still alive.
In particular the flaw appears to be a discrepancy between yarn planning dependencies and then executing. On a multi-workspace repo, I often run into this when performing a yarn upgrade-interactive --latest
. However, running a yarn upgrade
followed by another yarn upgrade-interactive --latest
will almost always allow it to proceed. Interestingly, running another yarn upgrade
often updates the lockfile further.
Essentially, my workaround is to alternate between yarn upgrade-interactive --latest
and yarn upgrade
until they succeed and make no further changes.
What I think is happening:
This is all speculation based on behavior and without any understanding of yarn's internals... but it follows what I imagine could be an easy false assumption when writing an optimizer and execution planner, and I figured I would toss this here in case it nudges somebody more familiar with the codebase toward a solution.
Not sure if it is a bug present in
yarn@2
, but we're testingyarn@2
next week under the same conditions to see if the same error crops up.
@bryanvaz do you have any update on this? How did it went?
Your mileage may vary on this one.
We've had success using yarn-deduplicate
to "solve" this situation: https://github.com/atlassian/yarn-deduplicate
Eventually the yarn.lock
grows in complexity again and the problem pops up, so then we need to run npx yarn-deduplicate yarn.lock
again to resolve it.
It changes your lockfile so some form of regression testing is necessary.
200 IQ "fix":
instead of using yarn add
, manually add the dependency to package.json
:shipit:
200 IQ "fix": instead of using
yarn add
, manually add the dependency topackage.json
:shipit:
I ran into this issue when running expo upgrade
in a mono-repo, which upgrades ~30 packages for given SDK version. I can't change every package version. So, the only way to do is downgrade yarn to 1.18.0
with
yarn policies set-version 1.18.0
Did npm install at the end. Phew!
I have been experiencing the same issues since
v1.19
.yarn upgrade-interactive
became unusable; It would fail to apply the version updates.After updating to
v1.21
I'm not able toyarn install
anymore. It always throws this error:expected workspace package to exist for ...
Downgrading to
1.18
fixed both issues.I should point out that these problems only occur on one project, which is a monorepo that uses
lerna
andyarn workspaces
.
Upgrading to 1.22.17
seems to fix this yarn upgrade-interactive
issue for me. I'm also in a monorepo project of lerna
with yarn
as its npmClient
and workspaces
. 🚝
Downgrading also works for me although I decided that it'd be better to upgrade to berry in the end. Works fine as long as you're not using zero-installs which I have never managed to make work.
An external but simple workaround would be to use volta (a toolchain manager) and pin to the downgrade version of yarn you need. This, of course, is just another alternative to the many workaround solutions proposed on this thread.
This is still reproduced in latest yarn v1.22.17
error An unexpected error occurred: "expected workspace package to exist for \"@typescript-eslint/eslint-plugin\"".
info If you think this is a bug, please open a bug report with the information provided in "/var/local/acp/dashboards/packages/vpn/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
200 IQ "fix": instead of using
yarn add
, manually add the dependency topackage.json
:shipit:
Still facing the same issue here, this is the only workaround that I've tried and works perfectly fine.
yarn: 1.22.17
node: 16.13.2
instead of using yarn add, manually add the dependency to package.json :shipit: Resolved by doing this ^, same as last comment ^
yarn: 1.22.17 node: 16.13.2
yarn upgrade-interactive
is still failing for me
yarn: 1.22.17 node: 16.13.2 && 16.14.0
Still failing for me...
yarn workspace test add chance
error An unexpected error occurred: "expected workspace package to exist for \"@jest/core\"".
Yarn: 1.22.17
Node: 16.14.0
Is downgrading yarn
three minor versions using yarn policies
still the workaround for this? Worked for me, but seems "bad".
just as an fyi for people still posting in here. This repo is abandoned by the devs and the new "yarn" is over here: https://github.com/yarnpkg/berry
we had to drop yarn completely due to no longer having an upgrade path
I deleted my yarn.lock file and and re-installed. That worked for me.
same issue
I deleted my yarn.lock file and and re-installed. That worked for me.
Avoid deleting/re-creating yarn.lock
file (it's there for a reason). Instead, try to dedupe its entries and then (re-)install.
EDIT (thanks to @as-zlynn-philipps for noticing my typo 😅 ):
npx yarn-deduplicate && yarn install
Avoid deleting/re-creating
yarn.lock
file (it's there for a reason). Instead, try to dedupe its entries and then (re-)install.npx yarn-dedupe && yarn install
I have been a full-stack developer for 10 years. I only ever delete my yarn.lock
as an absolute last resort. Trust me. And, in the last two months, I've encountered about 5 separate situations where that was the only thing that fixed a work-blocking issue. The issue in this thread is the latest one. The fix is as inexplicable as each issue itself.
So, at this point, I'm pretty desensitized to it. If deleting the yarn.lock saves hours of scouring GitHub issues, docs, and StackOverflow, just heckin' do it. If all your deps are following semver and your ranges are properly scoped in package.json, shouldn't break anything to just get the latest acceptable version of everything. That's my two cents. 🤷♂️
Re: deduping, this package actually dedupes: https://medium.com/@bnaya/yarn-deduplicate-the-hero-we-need-f4497a362128
It's almost like all this javascript tooling is insane :)
Millions of packages for every conceivable thing, hundreds of megabytes of node_modules
, tens of thousands of files... Yarn workspaces seems like it's yet another layer of indirection and abstraction on top of an already hideously complicated stack.
I had this problem and could solve it by setting all corresponding packages in all workspaces to the same version.
@as-zlynn-philipps the package you mentioned yarn-dedupe
is probably not the one you meant to mention yarn-deduplicate
: https://www.npmjs.com/package/yarn-deduplicate
@as-zlynn-philipps the package you mentioned
yarn-dedupe
is probably not the one you meant to mentionyarn-deduplicate
: https://www.npmjs.com/package/yarn-deduplicate
@Slapbox That was my mistake. He actually corrected it :)
It stopped failing for me once I fixed my workspace names.
package.json
packages/
hardhat/
package.json
ui/
package.json
root package.json:
"name": "web3-boilerplate",
"private": true,
"workspaces": ["packages/ui", "packages/hardhat"],
//etc
packages/hardhat/package.json:
"name": "@web3-boilerplate/hardhat",
"version": "1.0.0",
//etc
I previously had named the packages just hardhat
and ui
and this seems to have been causing the issue. Changing to @web3-boilerplate/hardhat
and @web3-boilerplate/ui
seems to have fixed it!!
Instead of downgrading yarn to 1.18.0
, @elenamik solution fixed it for us. It was a workspace package.json name: "@..."
issue. Thanks!
Also don't forget to remove your yarn.lock
.
How can this be? Yarn is broken for 8 months now and nothing is happening? Is the project dead?
Do you want to request a feature or report a bug? Bug
What is the current behavior?
yarn install
fails with:The error started occurring after upgrading yarn to
1.19
and it still persists in latest stable version1.21.1
Similar errors can be observed in #7797 and #7734
If the current behavior is a bug, please provide the steps to reproduce. The error can be reproduced when installing dependencies in https://github.com/callstack/haul
git clone git@github.com:callstack/haul.git
cd haul
yarn install
What is the expected behavior?
yarn install
should successfully install dependencies.Please mention your node.js, yarn and operating system version.
12.14.1
/13
(reproducible on both)1.21.1