How to install all the dependency package in yarn?

Viewed 22119

First, I'm new to React. I'm trying to use Google's Material-UI for my React project. In this tutorial, it says run npm install, but I heard using yarn and npm together in the same project because it might bring about some confusion between those two later. So, I'm trying to stick to yarn only.

npm install seems to install all the dependency package for the thing that I wanna use, but how can I do that in yarn? I tried yarn add, but it didn't work. How can I do that?

EDIT

Just found that it has only package.json, which means I can only use npm install to install dependencies. Would there be no problem when I use yarn later?

5 Answers

You should just be able to run yarn ("Running yarn with no command will run yarn install, passing through any provided flags." So just a simple yarn is what you'd want now, this answer previously suggested yarn install)

Here is a comparison table of most/all the commands you'd likely encounter


Edit Sept 2020: The newer versions of npm have greatly improved and caught up to yarn, so I currently have no clue what possible benefits yarn offers anymore, I'm 100% npm for the last year or so

The equivalent of $ npm install is just $ yarn (without arguments) to install all dependencies from package.json.

Also, just to clarify your query -

Just found that it has only package.json, which means I can only use npm install to install dependencies. Would there be no problem when I use yarn later?

Doesn't matter whether you use yarn or npm, there will always be a package.json.

And no, there won't be a problem when using yarn later.

You get package-lock.json when using npm, and yarn.lock file when using yarn. It's not recommended to use both yarn and npm for the same project, so you should remove either of package-lock.json and yarn.lock.

In my case it worked as - yarn global add @angular/cli (similarly any dependency) then added path "C:\Users\USER_NAME\AppData\Local\Yarn\Data\global\node_modules.bin" in "Edit the system environment variables" -> Environment Variables -> Under System Variables select PATH-> click New -> Add the above path then save-> Open new command prompt -> run the dependency command.

yarn install --force

From Yarn's help text on the install command:

--force   install and build packages even if they were built before, overwrite lockfile

I had a situation where nom install would install everything and yarn install wouldn't. So maybe try the other package manager?

Related