Can't create and run React Application - reactjs

I'm trying to run create-react-app but it seems it's not working the way it's supposed to. I'm trying the following command:
create-react-app my-app
cd my-app
npm start
and getting the following errors while trying to run
if you could help that'llenter image description here be great

The log you've shared says, creation is not success and you're using create-react-app version is very old.
Better you use npx which will ensure that you are using the latest version on the fly without any global installation. Try the below command
$ npx create-react-app festudents

Please remove globally create-react-app try this npm remove -g create-react-app
Then just run those commands
npx create-react-app my-app
cd my-app
npm start
Source: https://reactjs.org/docs/create-a-new-react-app.html

Try removing the creat-react-app boilerplate,
Then create a new with the following command
npx create-react-app my-app 2

Related

problem running create-react-app using npx

when I was trying to run create-react-app using the command npx create-react-app app I got the following Message
You are running `create-react-app` 4.0.1, which is behind the latest release (4.0.3).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
I then tried to uninstall create-react-app globally using npm uninstall -g create-react-app and rerun npx command again i still get the same message that I should uninstall create-react-app globally even so the only module that is installed globally is npm on my machine
You first need to uninstall the globally installed create-react-app and then, invalidate the cache.
Command for the same: npm uninstall -g create-react-app && npm cache clean -f
Now, you may continue with creating the application again using: npx create-react-app application-name.
This question is similar to this one.
Try npm cache clean –-force command after uninstalling create-react-app globally.
Hopefully, the following code will work:
npx create-react-app#latest my-app
Issue(#10601): https://github.com/facebook/create-react-app/issues/10601

How to make create-react-app use npm instead of yarn?

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

Template not provided using create-react-app

When I type the create-react-app my-app command in my terminal, it appears to work - downloading all libraries successfully etc. At the end of that process however I get a message that a template was not provided.
Input
user#users-MacBook-Pro-2 Desktop% create-react-app my-app
Output
Creating a new React app in /Users/user/Desktop/my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
..... nothing out of the ordinary here .....
✨ Done in 27.28s.
A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.
In package.json of my-app:
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0" <-- up-to-date
}
I checked out the CRA changelog and it looks like support was added for custom templates - however it doesn't look like the command create-react-app my-app would have changed.
Any idea what is going on here?
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.
Docs
Use either one of the below commands:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
if npm uninstall -g create-react-app stated above does not work.
Type which create-react-app to know where it is installed. Mine was installed in /usr/bin folder. Then do sudo rm -rf /usr/bin/create-react-app. (Credit to #v42 comment below)
1)
npm uninstall -g create-react-app
or
yarn global remove create-react-app
2)
There seems to be a bug where create-react-app isn't properly uninstalled and using one of the new commands lead to:
A template was not provided. This is likely because you're using an
outdated version of create-react-app.
After uninstalling it with npm uninstall -g create-react-app, check whether you still have it "installed" with which create-react-app (Windows: where create-react-app) on your command line. If it returns something (e.g. /usr/local/bin/create-react-app), then do a rm -rf /usr/local/bin/create-react-app to delete manually.
3)
Then one of these ways:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
Though already lots of answer is here.
I came up with 3 solutions which I applied step by step when I faced this situation.
First step: From Official manual,
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.
https://create-react-app.dev/docs/getting-started
You can use these commands below:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
Second step (If first one doesn't work):
Sometimes it may keep caches.then you can use these commands given below.
npm uninstall -g create-react-app
npm cache clean --force
npm cache verify
yarn create react-app my-app
Third step:(If these 2 won't work)
first uninstall via npm uninstall -g create-react-app,then check if you still have it "installed" with which create-react-app command on your command line. If you got something like (/usr/local/bin/create-react-app) then run this rm -rf /usr/local/bin/create-react-app (folder may vary) to delete manually.
Then again install it via npx/npm/yarn.
NB: I succeed in the last step.
First uninstall create-react-app globally by this command:
npm uninstall -g create-react-app
then in your project directory:
npm install create-react-app#latest
finally:
npx create-react-app my-app
To add up more to the answers above:
With the new release of create-react-app, you can create a new app using custom templates.
Two templates available so far:
cra-template
cra-template-typescript
Usage:
npx create-react-app my-app [--template typescript]
More details of the latest changes in create-react-app:
https://github.com/facebook/create-react-app/releases/tag/v3.3.0
I too had the same problem. When I trid the npm init react-app my-app command returned the same message
A template was not provided. This is likely because you're using an
outdated version of create-react-app.
But
yarn create react-app my-app command works fine.
Clear your npm cache first then use yarn as follows:
npm cache clean --force
npm cache verify
yarn create react-app my-app
I hope this helps.
EDIT
...you might want to try the following after I have looked into this problem further:
npm uninstall -g create-react-app
yarn global remove create-react-app
which create-react-app - If it returns something (e.g. /usr/local/bin/create-react-app), then do a rm -rf /usr/local/bin/create-react-app to delete manually.
npm cache clean --force
npm cache verify
npx create-react-app#latest
These steps should remove globally installed create-react-app installs, you then manually remove the old directories linked to the old globally installed create-react-app scripts. It's then a good idea to clear your npm cache to ensure your not using any old cached versions of create-react-app. Lastly create a new reactjs app with the #latest option like so: npx create-react-app#latest. There has been much confusion on this issue where no template is created when using npx create-react-app, if you follow the steps I have stated above (1-6) then I hope you'll have success.
p.s.
If I wanted to then create a react app in a directory called client then I would type the following command into the terminal:
npx create-react-app#latest ./client
Good luck.
npm install -g create-react-app in your pc
create react project again with npx create-react-app my-app
This worked for me.
npm uninstall -g create-react-app
npx create-react-app my-app
So I've gone through all the steps here, but non helped.
TLDR; run npx --ignore-existing create-react-app
I am on a Mac with Mojave 10.15.2
CRA was not installed globally - didn't find it in /usr/local/lib/node_modules or /usr/local/bin either.
Then I came across this comment on CRA's github issues. Running the command with the --ignore-existing flag helped.
These two steps worked for me
1) Uninstalled react-app globally with this command
npm uninstall -g create-react-app
2) Installed react-app in project folder with this command
npx create-react-app project-name
npx create-react-app#latest your-project-name
work for me after trying all the answers hope that can help someone in the future.
"If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version"
This is reported at https://create-react-app.dev/docs/getting-started/. For me, this did not work. I had to re-install create-react-app globally instead.
My steps to fix this problem were to:
npm uninstall -g create-react-app
npm install -g create-react-app
npx create-react-app my-app
All of the option didn't work for me on MacOS. What did work was the following 3 steps:
Delete the node from: /usr/local/bin/
then
install node newly: https://nodejs.org/en/
then
Install react: npx create-react-app my-app follow: https://create-react-app.dev/
For Linux this worked for me
sudo npm uninstall -g create-react-app
npx create-react-app my-test-app
TLDR: Uninstall the global package using npm uninstall -g create-react-app and generate new react apps using npx create-react-app app.
Issue
You're using an older version of create-react-app that you have installed globally using npm. The create-react-app command invokes this global package.
You could've confirmed that you were using an outdated version by running npm outdated -g create-react-app or comparing create-react-app --version with npm view create-react-app.
The fact that the version of react-scripts was up to date, has nothing to do with the version of the package that is bootstrapping the app (create-react-app), which grabs the latest versions of the packages that it uses (react-scripts in this case).
Solution
If you want to continue using the create-react-app command, you'll need to update the global package using npm update -g create-react-app. Note that you'll want to do this periodically to keep it up to date. You'll notice that create-react-app does not recommend this (noted in the logs from your install).
A better approach would be to delete the global install entirely (npm uninstall -g create-react-app) and instead use npx so that it grabs the latest version of the package every time (more detail on npx below).
You should confirm that it was uninstalled globally by trying to use create-react-app to make sure the command is "not found".
Issues with uninstalling?
You can debug where it was installed using which create-react-app. If you're having issues uninstalling it, you may have multiple versions of node/npm on your machine (from multiple installs, or because you use a node version manager such as nvm). This is a separate issue I won't address here, but there's some info in this answer.
A quick nuclear approach would be to forcefully remove it (rm -rf) at the path that which create-react-app returns.
Supplement
Global npm packages and the npx command
$ NPM_PACKAGE_NAME will always use the globally installed version of the package, regardless of which directory you're in.
$ npx NPM_PACKAGE_NAME will use the first version of the package that it finds when searching up from the current directory to the root:
If you have the package in your current directory, it will use that.
Else if you have the package in a directory that is a parent of your current directory, it will use the first one it finds.
Else if you have the package installed globally, it will use that.
Else if you don't have the package at all, it will temporarily install it, use it, and then discard it. - this is the best way to ensure the package is up to date.
More info about npx can be found in this answer.
Using npx with create-react-app
create-react-app has some special commands/aliases to create a react app (instead of npx) that are specific to that package (yarn create react-app, npm init react-app), but npx create-react-app will work the same as it does with other packages.
yarn vs npm global installs
Yarn stores global installs in a different folder than npm, which is why yarn create react-app would work immediately without uninstalling the global npm package (as far as yarn is concerned, the package hasn't been installed).
This is just a temporary solution though, as you'll need to remember to always use yarn instead of npm when using Create React App.
This works for me!
1) npm uninstall -g create-react-app
2) npm install -g create-react-app
3) npx create-react-app app_name
If you have any previously installed create-react-app globally via npm install -g create-react-app, Better to uninstall it using npm uninstall -g create-react-app
This solved my problem
Steps:
1.Uninstall the create-react app
npm uninstall -g create-react-app
2.Now just use
npx create-react-app my-app
this will automatically create the template for u .
This problem is not solved like this, the problem is in the different instances of node, try removing globally create-react-app and then delete the node_modules and package-lock.json from your root user
This work's for me :
Let's, uninstall create-react-app globally by this command:
npm uninstall -g create-react-app
After that in your project directory:
npm install create-react-app#latest
At the last:
npx create-react-app my-app
For typescript :
npx create-react-app my-app --template typescript
First uninstall create-react-app
npm uninstall -g create-react-app
Then run yarn create react-app my-app or npx create-react-app my-app
then running yarn create react-app my-app or npx create-react-app my-app may still gives the error,
A template was not provided. This is likely because you're using an outdated version of create-react-app.Please note that global installs of create-react-app are no longer supported.
This may happens because of the cashes. So next run
npm cache clean --force
then run
npm cache verify
Now its all clear. Now run
yarn create react-app my-app or npx create-react-app my-app
Now you will get what you expected!
I fix this issue on Mac by uninstalling create-react-app from global npm lib, that's basically what said, just try to do, you need also do sudo:
sudo npm uninstall -g create-react-app
Then simply run:
npx create-react-app my-app-name
Now should be all good and get the folder structures as below:
Using the command npm uninstall -g create-react-app didn't work for me.
But this worked:
yarn global remove create-react-app
and then:
npx create-react-app my-app
Such a weird problem because this worked for me yesterday and I came across the same error this morning. Based on the release notes, a new feature was added to support templates so it looks like a few parts have changed in the command line (for example, the --typescript was deprecated in favor of using --template typescript)
I did manage to get it all working by doing the following:
Uninstall global create-react-app npm uninstall create-react-app -g.
Verify npm cache npm cache verify.
Close terminal. I use the mac terminal, if using an IDE maybe close and re-open.
Re-open terminal, browse to where you want your project and run create-react-app via npx using the new template command conventions. For getting it to work, I used the typescript my-app from the documentation site to ensure consistency: npx create-react-app my-app --template typescript
If it works, you should see multiple installs: one for react-scripts and one for the template. The error message should also no longer appear.
npm uninstall -g create-react-app could be an answer in some cases, but not in mine.
You should manually delete your create-react-app located at ~/.node/bin/ or /usr/bin/ (just type which create-react-app and remove it from locations you saw using rm -rf), next just run npm i -g create-react-app.
After that create-react-app will be working correctly.
This worked for me
1.First uninstall create-react-app globally by this command:
npm uninstall -g create-react-app
If there you still have the previous installation please delete the folder called my app completely.(Make sure no program is using that folder including your terminal or cmd promt)
2.then in your project directory:
npm install create-react-app#latest
3.finally:
npx create-react-app my-app
For any Windows users still having this issue, this is what fixed it for me:
Run where create-react-app to get the path (mine was in C:\Users\username\AppData\Local\Yarn\bin).
Navigate to that directory and delete both "create-react-app" and "create-react-app.cmd".
Navigate to the directory you want to start a project in.
Run npm install create-react-app,
npx create-react-app name-of-app,
cd name-of-app, yarn start.
Step #4 will vary based on your configuration, but that's just what got me up and running.
One of the easiest way to do it is by using
npx --ignore-existing create-react-app [project name]
This will remove the old cached version of create-react-app and then get the new version to create the project.
Note: Adding the name of the project is important as just ignoring the existing create-react-app version is stale and the changes in your machines global env is temporary and hence later just using npx create-react-app [project name] will not provide the desired result.
npx create-react-app#latest {project name}
this seems to be the way to make it work.
After using this command:
yarn global upgrade create-react-app
I then tried:
yarn create-react-app my-app but it didn't work for me.
This worked though:
npx create-react-app my-app

create-react-app doesn't generate public and src folders thus cannot get started

i have installed CRA for over a month and have been working with it without having any problems, however today i created a new react app and it builds the folders and directories except it doesn't generate src and public folder(it just generated node-modules folder) thus when i run npm start it gives me an error saying:
npm ERR! missing script: start
Initially you might have installed create-react-app globally.Try to remove using npm uninstall -g create-react-app command and then try npx create-react-app <your-app-name>.
The reason is, npx should use it's latest version to work. Hope your doubt is now cleared
I still have no idea what was the reason but I got it working doing these:
-uninstalled create-react-appusing npm uninstall -g create-react-app.
-using npx create-react-app app-name I created a new app and now it's working as expected.
I have tried installing in different computers and for most cases the above codes helped to fix the issue. But in a rare case I had to use another code and it worked perfectly. Try running the below code
npx --ignore-existing create-react-app Your-AppName
I tried all the suggestions stated above but none works for me.I just run these commands and create a new project.
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app#latest my-app
This work for me.
You can create project with yarn:
yarn create-react-app my-app

public, src,and scripts folder not created while using create-react-app

I am trying to create a new project using create-react-app using the command given on the docs i.e npx create-react-app my-app but it doesn't contain folders like public src and script.
Try with these steps :
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app
Source
I tried all the suggestion stated above but none works for me. This suggestion at 8097 works for me. Basically, I just run npx create-react-app#latest your-project-name
For those who keep trying and still doesn't work, you might have the same problem as me.
Because the global installs of create-react-app are no longer supported you might have it installed on your machine, thus have the old version running whenever you try to npx create-react-app. There are 2 very easy steps: remove create-react-app, then run the npx command.
It will look like this:
sudo npm rm -g create-react-app (sudo is needed on macs to grant you permission, it will ask for your password, type it in and hit enter)
npx create-react-app my-app
Should solve your problem there
Still didn't got to know the issue. But i tried :-
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app
This also didn't worked for me. So I uninstalled node and installed it again. It worked for me
If someone's terminal get stuck and the initialization does not completes, just open the resource monitor and resume the cmd ,
1.window+R key- type 'resmon'
2.Locate the cmd process ,right click and resume it, initialization will be complete.
had the same issue on my mac.
The correct way is if you've previously installed create-react-app globally via npm install -g create-react-app, you have to uninstall the package using npm uninstall -g create-react-app in order npx to uses the latest version.
Tips: Try npx create-react-app --info to check if npmGlobalPackages includes create-react-app. If cra is included then try the below command which create-react-app and rm -rf the outputted path.
Last but not least, force npx to use latest:
npx create-react-app#latest your-project-name
You can uninstall a globally installed package with this:
npm uninstall -g create-react-app
Install Npm version of
14.18.2
Install Below Link: https://nodejs.org/dist/v14.18.2/win-x64/node.exe
It is not working for me on windows machine. It worked when I ran below commands from git bash:
npm install -g create-react-app
npx create-react-app my-app
Follow the following steps and that should solve your problem.
sudo npm rm -g create-react-app (Do not skip sudo if you are a macOS user).
npx create-react-app my-app (npm 5.2+ and higher)
or
npm init react-app my-app
or
yarn create react-app my-app (if you use yarn)
I had the same problem, this how I solved it.
When I try to run npm rm -g create-react-app, it shows an error.
So I went to the node modules directory (for Mac /usr/local/lib/node_modules) and delete create-react-app directory and reinstall create-react-app using npx create-react-app my-app.
For Windows users who are facing this issue:
Open Task Manager and check if the Windows Command Processor process is set to Suspended.
If it is set to Suspended, open Resource Monitor and click on the CPU tab.
From within the CPU tab, locate and right-click on cmd.exe and and select Resume Process.
Click the source link below for a more detailed explanation (including screenshots).
Source: Github Issues
I solved it using following commands
npm uninstall -g create-react-app
yarn global add create-react-app
In my case, i tried installing with yarn but don't downloaded all files
So I tried this
npm install --global yarn
npm uninstall -g create-react-app
npm install -g create-react-app
npx create-react-app my-app-youtube --use-npm
And it worked, with npm, i downloaded all template
:D
Ok ok... If you are still not getting any solution
Go to other Folders of your computer(like documents, Downloads) and then Create a folder for your app and Open it with VsCode(preferable)
On the Terminal ( Or Powershell which is also avaliable in VsCode)
1st Command: npm uninstall -g create-react-app
2nd Command: npx create-react-app
Hope It Helps :)

Resources