Today I created a reactjs starting template with CRA using:
npx create-react-app my-app --template redux
This created two files in my project: package.json
and yarn.lock
.
I am confused about why it worked after I cd
in the project and ran yarn start
even though I didn't initiate the project with yarn create react-app my-app
.
I have two questions:
npx create-react-app my-app --template redux
andyarn create react-app my-app --template redux
considering that they have the same effect.yarn install is used to install all dependencies for a project. This is most commonly used when you have just checked out code for a project, or when another developer on the project has added a new dependency that you need to pick up. If you are used to using npm you might be expecting to use --save or --save-dev .
There is no Yarn equivalent for npx . The Yarn team thought npx was enough. That being said, we support creating a new Preact CLI project with Yarn through the --yarn flag. Please do note that when using Preact CLI via NPX, you do need to use preact-cli .
npx locally installs all node packages for a specific project. Yarn is a different package, but faster than npm and npx, most of the developers use yarn for node modules installation.
Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node. js module resolution algorithm.
npx create-react-app
executes create-react-app
binary, and create-react-app
uses yarn
to create your project (if yarn is installed). that's why you can see yarn.lock
and also why yarn-start
works.
Difference between
npx create-react-app
andyarn create react-app
They both executes create-react-app
binary. create-react-app
is the one who decides whether it wants to create the project with yarn or not. to use npm
in create-react-app
, use --use-npm
flag (no matter you execute create-react-app
with npx
or yarn
or directly
, you should set it if you want it to use npm
.):
create-react-app my-project --use-npm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With