yarn-v2

Yarn 2 init, add failing


I'm experimenting with yarn 2 and faceplanting.

I created a new folder: /projects/yarn2/

As per their install guide https://yarnpkg.com/getting-started I ran

cd /projects/yarn2/
yarn set version berry
yarn init

then (as per their guide https://yarnpkg.com/getting-started/usage )

yarn add react

and got the following error:

Usage Error: The nearest package directory (/projects/yarn2) doesn't seem to be part of the project declared in /projects.

- If the project directory is right, it might be that you forgot to list yarn2 as a workspace.
- If it isn't, it's likely because you have a yarn.lock or package.json file there, confusing the project root detection.

$ yarn add [--json] [-E,--exact] [-T,--tilde] [-C,--caret] [-D,--dev] [-P,--peer] [-O,--optional] [--prefer-dev] [-i,--interactive] [--cached] ...

What am I doing wrong?


Solution

  • Check to see if you have a package.json or yarn.lock file in your /projects directory. If you do, clear it/them out and this should start working.