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.
Related
My project was initialized using npm and for a long time I had been working with npm, now I wanted to switch to yarn, since this solves some problems, the question is how to create-react-app so that by default it offers to update using yarn instead of npm
That is, yes, I can update my packages with yarn, but I would like create-react-app itself to offer an update using yarn
First, you need to have yarn installed in your computer.
Follow instruction on https://classic.yarnpkg.com/en/docs/install
Then, create-react-app will use yarn by default, as explained here:
https://create-react-app.dev/docs/getting-started/#selecting-a-package-manager
Note:
If you are trying to update an already existing app, then delete package-lock.json and node_modules, and install dependencies again with yarn:
rm -rf node_modules
rm package-lock.json
yarn install // will create a new yarn.lock file
Did you try:
yarn create <starter-kit-package> [<args>]
e.g:
$ yarn global add create-react-app
https://classic.yarnpkg.com/en/docs/cli/create/
I just delete npm from my project and leave only yarn localy and its work fine
I have the following error with npm start in my React application:
The react-scripts package provided by Create React App requires a dependency:
"webpack-dev-server": "3.11.1"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack-dev-server was detected higher up in the tree:
C:\Users\Username\node_modules\webpack-dev-server (version: 3.11.0)
Usually I fixed this type of issue by running the following code: npm install react-scripts#latest.
But now it seems like that React is not updated yet to the latest webpack-dev-server
Now the question is how to fix that. By the way, I use npx create-react-app for my project, Thanks!
I have write following commands in react project
Open project in command prompt
npm uninstall -g webpack-dev-server
remove web-dev-server folder from node_modules(C:/Users/UserName/Node_Modules)
npm i -g webpack-dev-server#3.11.1
remove package-lock.json and write npm install
after it your react project may be start by npm start
First, remove the node_modules folder and yarn-lock or package-lock.json file.
And, then add this line in your .env file:
SKIP_PREFLIGHT_CHECK=true
Now you can do npm start or yarn start after re-installing the packages. It should work.
Explanation:
For some reasons, you have two versions of webpack-dev-server installed in your project's node_modules. By setting SKIP_PREFLIGHT_CHECK=true in .env file, we are telling npm to ignore such version issues.
Check if node_modules and package-lock.json are present in your home folder, instead of your project folder. If yes, delete those two folders and then go for npm start.
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:
Why it generated yarn.lock?
What is the difference between
npx create-react-app my-app --template redux and
yarn create react-app my-app --template redux considering that they have the same effect.
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 and yarn 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
create-react-app uses yarn for the setup if it's installed.
So, if yarn is already installed in your system, then npx create-react-app my-app --template redux and yarn create react-app my-app --template redux would give you the same end-result.
And it is already installed in your system, that's why it has generated yarn.lock and not package.lock.
yarn.lock is generated to keep the exact version of the installed packages.
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 want to try React on my Mac, but I face some difficulties when using it.
I installed create-react-app globally with
npm install -g create-react-app
But everytime I create a new project I have a huge node_modules folder in my project folder. AFAIK I don't need node_modules folder in every project if create-react-app installed globally. So what's the problem?
When I tried to uninstall create-react-app to install it again (just to be sure I installed it globally) I get an error saying
npm remove -g create-react-app
Error: EACCES: permission denied, unlink 'usr/local/bin/create-react-app'
So what do I do in this case?
The node_modules folder you see for every project is node_modules for that specific project. This is how all javascript projects that use npm work. You don't want all the dependencies of every project installed globally. That would run into all kinds of issues with different versions of packages etc.
This error indicates that you probably ran npm install -g create-react-app as either root or as sudo like so: sudo npm install -g create-react-app. Try running sudo npm remove -g create-react-app and see if that works.
I couldn't use the new version of create-react-app with npx, so I tried to remove via the command npm uninstall -g create-react-app. After that when I checked it still has "installed". So I have removed manually
rm -rf /usr/local/bin/create-react-app
But everytime I create a new project I have a huge node_modules folder
in my project folder.
That node_modules folder store all the local dependencies for that particular project with specific versions as mentioned in package.json and its dependencies also. It is required for every project, unless all dependencies of your project are global and match the versions perfectly which never would be the case AFAIK.
Use npm uninstall -g package_name for removing package.
Also its better if you use npx for create new react projects. But this would only work properly if npm version is above 5 and you have to uninstall global create-react-app first.
npx create-react-app my-app
I hard similar issue with mine. I did
npm uninstall -g create-react-app
and it worked.
this may sound odd but it work many times
if this kind of error come than run code in your terminal
npm uninstall -g create-react-app
if not work than without any headache run
npm i create-react-app
in your root folder this will update the react app in your system after this untill next latest version you can enjoy with
npx i create-react-app my-app