The npm init react-app my-app command imports many packages to the project, but, why this dependencies are not in the package.json?
The dependencies are in the package.json of react-scripts which your project will depend on when initializing it. The only dependency of your project will be react-scripts.
If you want to manage these yourself you need to eject your project.
Related
I'm trying to create a react app using yarn create react-app but the dependencies are being installed on .yarn folder. Do you know how can I fix that and install the dependencies on node_modules folder?
You are going to want to use yarn create react-app appname
An alternative would be npx create-react-app appname, but the command you mentioned won't do what you are trying to accomplish.
Then to install the dependencies enter the directory you just created by using cd appname and then yarn install.
I read the documentation of reactstrap, and it guide us to install npm package as below;
npm install --save bootstrap
npm install --save reactstrap react react-dom
my question is, is it necessary to install react and react-dom, aren't those two packages are included by default in create-react-app?
Yes, it's installed by default when you are make
npx create-react-app my-app
You alse can instal it with typescript if you want via
npx create-react-app my-app --template typescript
and it will also add #types/react-dom
Yes! it is included in node_modules by default when you use
npx create-react-app app-name
but you may also choose not to use it for some reason. Then you will need to install them and add your project starting files by yourself.
I am trying to install and use the eslint-plugin-react-hooks plugin in a project. Usually I'd simply run npm install or yarn add but the directions say to use react-scripts because I'm using create-react-app. How do I do that? Do I add a script and list it as a dependency on the package.json file or is there some other way?
Any help is appreciated.
I kind of rushed into creating a React app based on a tutorial that used yarn. Now I'm going to re-create the app from scratch because I'm not satisfied with the reactstrap library, and I'd like to switch to react-bootstrap.
I've re-installed node. However, when I run create-react-app, it says to use "yarn" instead of "npm" as follows:
yarn start
Starts the development server.
yarn build
Bundles the app into static files for production.
yarn test
Starts the test runner.
yarn eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd react-test
yarn start
I'd like to use npm because it seems like it's more widely used and there are more examples based on it. Am I stuck with yarn, or can I go ahead and use npm?
You can either
1) Remove yarn.lock, and running npm i,
or
2) Run create-react-app app --use-npm
1 ⇢ If you have installed create-react-app then use:
create-react-app --use-npm
2 ⇢ If you are using npx command then use:
npx create-react-app --use-npm
3 ⇢ For existing yarn app, remove the yarn.lock file and run:
npm i
or
npm install
Install create-react-app npm i -g create-react-app --use-npm
Go to desired path using cd command
Add --use-npm create-react-app my-app-name --use-npm
This command will create a folder with the name that you mentioned inside your current path . This folder consists all necessary configuration files needed for a starter code for react application
# Run this to create-react-app using npm
npx create-react-app my-app
# Or run this to create-react-app using yarn
yarn create react-app my-app
I dont know if this helps. But I was having the same problem and did this
npx expo-cli init --npm
and it installed with npm
hope this helps you or someone in the future
For latest versions, the flag is changed to --npm
So if you want to use npm then use it like
npx react-native init YourProject --npm
I learned about Yarn and wanted to try it with React so I installed Yarn, and now when I run create-react-app hello, one of the scripts appear to be yarn add v0.24.6, which installs 879 dependencies into my node_modules directory.
Why is this happening and how do I make it stop? Or do I just not understand Yarn and this is supposed to be something I want?
Were you using npm2 before? With it, you'd only see your app's direct dependencies in node_modules and their dependencies (i.e. your app's transitive dependencies) would be tucked away in nested node_modules dirs.
Yarn and npm >= 3 flatten dependencies in node_modules, so you're seeing all of react-scripts' direct dependencies and all of its transitive dependencies.
Every package we use might depends on others packages.
yarn and npm > 3 use flat structure for resolving dependencies of other packages dependencies. So, your node_modules folder container long list of folders.
npm < 3 use nested tree structure. So, your node_modules folder container few list of folders and dependencies of other packages nested inside package/node_modules folders.
so, why use npm > 3 or yarn?
Those are fast for resolving dependencies. I hope you have not yet experience on waiting for 1hours or more after npm install :D.
why yarn over npm?
There are lots of articles written on this topic. Just google it.