How to make create-react-app use npm instead of yarn?
Asked Answered
E

8

55

I kind of rushed into creating a React app based on a tutorial that used yarn. Now I'm going to re-create the app from scratch because I'm not satisfied with the reactstrap library, and I'd like to switch to react-bootstrap.

I've re-installed node. However, when I run create-react-app, it says to use "yarn" instead of "npm" as follows:

  yarn start
    Starts the development server.

  yarn build
    Bundles the app into static files for production.

  yarn test
    Starts the test runner.

  yarn eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd react-test
  yarn start

I'd like to use npm because it seems like it's more widely used and there are more examples based on it. Am I stuck with yarn, or can I go ahead and use npm?

Expendable answered 21/5, 2020 at 15:53 Comment(0)
B
123

You can either

1) Remove yarn.lock, and running npm i,

or

2) Run create-react-app app --use-npm

Brodie answered 21/5, 2020 at 15:57 Comment(2)
Will this impact the app I created with yarn?Expendable
Nope. It will be fine as long as you remove yarn.lock. This should remove the traces of it and any version conflicts. If you want to play safe, you can remove node_modules, before running npm i. This in turn will reinstall the dependencies and generate the package-lock.json.Brodie
R
11

1 ⇢ If you have installed create-react-app then use:

create-react-app --use-npm

2 ⇢ If you are using npx command then use:

npx create-react-app --use-npm

3 ⇢ For existing yarn app, remove the yarn.lock file and run:

npm i

or

npm install
Regression answered 9/10, 2021 at 3:38 Comment(0)
B
1
  1. Install create-react-app npm i -g create-react-app --use-npm
  2. Go to desired path using cd command
  3. Add --use-npm create-react-app my-app-name --use-npm This command will create a folder with the name that you mentioned inside your current path . This folder consists all necessary configuration files needed for a starter code for react application
Backspace answered 22/6, 2021 at 3:55 Comment(0)
A
1

# Run this to create-react-app using npm

npx create-react-app my-app

# Or run this to create-react-app using yarn

yarn create react-app my-app
Advanced answered 24/11, 2022 at 13:24 Comment(0)
K
0

I dont know if this helps. But I was having the same problem and did this

npx expo-cli init --npm

and it installed with npm

hope this helps you or someone in the future

Kainite answered 29/10, 2020 at 16:54 Comment(4)
The OP specifically asked for create-react-app, not Expo.Artemisa
Yeah, that's for React Native. This for React.Matter
That command is for React Native using Expo, whereas the question is for React using create-react-app.Straphanger
I came here looking for a react native answer. Thank youForeclose
L
0

For latest versions, the flag is changed to --npm So if you want to use npm then use it like

npx react-native init YourProject --npm
Lascar answered 13/11, 2022 at 6:16 Comment(0)
M
0

The same problem comes to me. I used "create-react-app --use-npm". It works.

Markle answered 6/9, 2023 at 13:33 Comment(0)
T
0

If you want to create react app by simple npm (not npx):

npm init react-app my-app
Talaria answered 12/7 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.