How to use npm instead of yarn with the “expo init” cli (react native tip)

orama254

RamaDevsign

Posted on September 23, 2021

How to use npm instead of yarn with the “expo init” cli (react native tip)
tl:dr  —  run expo init ‘project_name’ --npm



In this guide, I’ll show you how to use npm instead of yarn to create a new react native project while working with the expo cli. React Native combines the best parts of native development(Android, IOS) with React, a best-in-class JavaScript library for building user interfaces. Expo on the other hand makes this process super easy.

Prerequisites

This guide assumes that you have already installed the expo cli globally. You can find a comprehensive guide on how to set that up on the official expo documentation

The Problem

You might have at one point installed yarn on your machine to follow along with a coding tutorial or as a requirement on a past project you were working on. You now have both yarn and npm installed on your machine and you don't want to uninstall either of them(for whatever technical 'it depends' reason). By default expo cli falls back to yarn when it is available but due to preference you want to use npm.

The Solution

The solution in this case is to use the --npm flag when initializing a new expo react native project. The cli hints at what you should use but doesn't explicitly describe where it should be used. This is done by typing expo init project-name with the --npm flag.

e.g

expo init unicornfinder --npm
Enter fullscreen mode Exit fullscreen mode

With the expo init 'project-name' --npm statement, you can now initialize your application with npm as its default package manager. Remember that you will have to run the expo init command with the --npm flag everytime you want a new project to use npm as your preferred package manager.

Thanks for reading and Happy coding!!

💖 💪 🙅 🚩
orama254
RamaDevsign

Posted on September 23, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related