The nearest package directory doesn't seem to be part of the project
See original GitHub issueDescription
We have a monorepo with a package.json
in the root that lists the workspaces:
"workspaces": [
"packages/core/*",
"packages/react/*",
],
I wanted to upgrade our version of Yarn so I removed all node_modules
and our yarn.lock
in root and tried yarn
after the upgrade but got the following error:
Usage Error: The nearest package directory ({path}) doesn't seem to be part of the project declared in {path}.
This used to work fine with .yarn/releases/yarn-berry.js
but not with .yarn/releases/yarn-2.4.0.cjs
.
Solution
I created an empty yarn.lock
in the root and tried yarn
again and everything worked.
This was all a bit unintuitive. I’m not sure if maybe the error should suggest that as a solution or if it should just create one for me(?) but thought I’d raise for discussion.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:23 (14 by maintainers)
Top Results From Across the Web
Yarn 2 init, add failing - Stack Overflow
Usage Error : The nearest package directory (/projects/yarn2) doesn't seem to be part of the project declared in /projects.
Read more >Nextjs Fix Usage Error - The nearest package directory
... Error: The nearest package directory (C:\Users\user\Desktop\websites\nextjs-starter) doesn't seem to be part of the project declar...
Read more >usage error: the nearest package directory doesn't seem to be ...
usage error : the nearest package directory doesn't seem to be part of the project declared in. Add Answer | View In TPC...
Read more >Having strange problem with create-next-app... : r/nextjs - Reddit
Usage Error : The nearest package directory (C:\Users\mrcrispy\source\Projects\testingnext) doesn't seem to be part of the project declared ...
Read more >Workspaces - Yarn
How to use it? Add the following in a package.json file. Starting from now on, we'll call this directory the “workspace root” ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The error happens when you have a
yarn.lock
(orpackage.json
) file higher up in the filetree, at that point Yarn thinks you’re in a workspace you haven’t declared and throws.Maybe clearer expression of my idea is: Yarn 2 tries to exercise control outside of the current project upwards, without boundaries, I think it is not right. Yarn should exercise control inside project boundaries and it should not bother Yarn what is upwards in directory hierarchy, if there is
yarn.lock
,package.json
or anything else upwards in the directory hierarchy. In order to exercise control within project boundaries Yarn should not miss real project boundary and go upwards past it, how to do it right is a separate question.