question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The nearest package directory doesn't seem to be part of the project

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:23 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
merceyzcommented, Dec 4, 2020

The error happens when you have a yarn.lock (or package.json) file higher up in the filetree, at that point Yarn thinks you’re in a workspace you haven’t declared and throws.

3reactions
larixercommented, Dec 4, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found