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> ...
CoryCoolguy
  • 1,065
  • 8
  • 18
Ramesh
  • 13,043
  • 3
  • 52
  • 88

2 Answers2

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"
jclyons52
  • 306
  • 3
  • 8
  • is `yarn create react-app` a typo? It shouldn't have a space? – dwjohnston Sep 07 '21 at 00:29
  • 2
    no it's not a typo https://classic.yarnpkg.com/en/docs/cli/create/ – jclyons52 Sep 07 '21 at 00:38
  • 1
    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" ? – Kzqai Jan 17 '22 at 23:54
  • You should just use `npm install -g yarn@berry`, since the latest tag is Yarn Classic (1.x) – Maytha8 Jan 29 '23 at 10:20
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

  • 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. – dwjohnston Sep 07 '21 at 00:30