I am trying to migrate from NPM to Yarn for the sole reason of getting rid of 'node_modules' folder.
I am trying to use CRA tool. However, on CRA it advises to use yarn create
, which is not a command found in Yarn 2 documentation. After some research I found out that I should use yarn dlx
command, which is equivalent to npx
.
The problem is that to use yarn dlx
, I must have Yarn 2 first. Yarn 2 requires that I install it locally in my project directory. This way, I am forced to have a second layer of folder structure.
I want to create-react-app
in a folder on my Desktop called myApp. But, I need to create myApp folder to install Yarn 2 before I can even start using dlx to run create-react-app
.
Am I missing something?
Thank you.
Yes, for now, you have to use the second layer of the folder structure.
Assuming you have the latest version of Node 14.x, 16.x or any higher versions, the minimal instructions are the following.
Prerequisites:
corepack enable
command. This needs to be done only once.Steps:
mkdir enclosing; cd enclosing
- to create enclosing directoryyarn set version stable
- to use latest stable Yarn version in the eclosing directory and all of its subdirectoriesrm package.json
- deletepackage.json
in the enclosing directory, generated by the previous command to not confuse Yarn that the enclosing directory is the root of the project.yarn create react-app my-app
- the project will be generated with Yarn 3 and by default will use PnP install schemecd my-app; yarn set version latest
- to attach Yarn 3+ tomy-app
projectnode_modules
install scheme with Yarn 3+, insidemy-app
runyarn config set nodeLinker node-modules
After that, you can move out
my-app
anywhere and deleteenclosing
directory.In order to simplify all this into
yarn dlx create-react-app
I have opened pull request tocreate-react-app
, please place a thumb up emojo for it here: https://github.com/facebook/create-react-app/pull/12366