9

In yarn v1 we initialize create react app using yarn create react-app my-app. How to initialize the same in yan v2.

The above command gives the error

Usage Error: No project found in <<directory>>

$ yarn run <scriptName> ...

2 Answers 2

6

Check your yarn version:

yarn --version

If it's below 1.22 you may need to upgrade it to use yarn 2:

npm install -g yarn

You can then create your app:

yarn create react-app my-app
cd my-app
yarn set version berry
yarn
yarn start

This should have your react app up and running using yarn 2. You may want to remove the node_modules folder:

rm -R node_modules

Also, you need the next line on .yarnrc.yml

nodeLinker: "node-modules"
Sign up to request clarification or add additional context in comments.

4 Comments

is yarn create react-app a typo? It shouldn't have a space?
Not sure why you rm -R node_modules here and then set the nodeLinker to node-modules in the yarnrc? Seems like whatever that is designed to accomplish, it would require an additional run of yarn install after that which would recreate the node_modules because you've moved away from nodeLinker: "pnp" ?
You should just use npm install -g yarn@berry, since the latest tag is Yarn Classic (1.x)
3

You can use yarn dlx create-react-app my-app. It will work. There are a lot of changes came with the yarn version2 update. check this also for additional info: https://dev.to/arcanis/introducing-yarn-2-4eh1

1 Comment

This doesn't work particularly well within a yarn 2 monorepo - it will also add the .pnp.cjs file, .yarn folder into the package folder, rather than it being at the root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.