7

I'm installing a new react app using nextjs docs:

npx create-next-app

for some reason its using yarn by default:

enter image description here

I'm used to working with npm commands, how can I fix it please ?

2 Answers 2

10

EDIT: npx create-next-app my-app --use-npm

https://github.com/vercel/next.js/issues/10647

OLD ANSWER: Remove yarn.lock and node_modules/

rm yarn.lock
rm -rf node_modules

install your dependencies with npm:

npm install

this will create a package-lock.json file, analogous to yarn.lock.

6
  • if i remove node_modules, wont it delete all the modules nextjs is using ? I've seen on youtube people using npx ... and the instalation used npm and not yarn.. Jun 28, 2020 at 15:11
  • 1
    Running npm install will read package.json and install the libraries listed in dependencies. Just don't delete package.json. Jun 28, 2020 at 15:31
  • not working right.. I'm trying to understand why it's using yarn in the first place .. Jun 28, 2020 at 15:55
  • 1
    It's intended. If you have yarn in your machine, it'll use that by default. I have edited the answer. Jun 28, 2020 at 16:02
  • I am seeing the opposite behavior. I want yarn but npm is used by default. May 11, 2021 at 9:27
1

I tried the answer by @Rodrigo Amaral but faced several errors.

Before deleting the node_modules and yarn.lock, I ran npm install, which created a package-lock.json.

So the workflow is

npm install

rm yarn.lock

rm -rf node_modules

npm install

This should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.