Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn 2 init, add failing

Tags:

yarn-v2

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?

like image 840
Dan Pouliot Avatar asked Sep 24 '20 14:09

Dan Pouliot


People also ask

How do you fix a yarn error?

The easiest way to fix it is to use git checkout --theirs yarn. lock , and follow up with yarn install again (which can be followup by yarn cache clean to remove any file that wouldn't be needed anymore). This will cause the v1 lockfile to be re-imported.

How do you initialize yarn?

Setting defaults for yarn init The following config variables can be used to customize the defaults for yarn init : init-author-name. init-author-email. init-author-url.

How do I install a yarn error?

To solve the error "yarn: command not found", install the yarn package globally by running npm install -g yarn and restart your terminal. If the command fails, run it with sudo and make sure the correct PATH is set in your system's environment variable.

How do I install all dependencies on yarn?

To install dependencies, you have to run yarn install in the root of your directory to install all the dependencies for a project. The dependencies will be retrieved from the package. json file you pushed to version control, and will be stored in the yarn. lock file.


1 Answers

You either don't have package.json or yarn.lock which confuses yarn if the package is added in the workspace or not. Just run the following command and I think your problem must be solved.

cd <folder_name>/<project_name>

touch yarn.lock

yarn

like image 181
Aryan Pitliya Avatar answered Jan 03 '23 16:01

Aryan Pitliya