did i install create-react-app incorrectly? - reactjs

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

Related

Why can't I delete global NPM package on Ubuntu?

I have this problem, I follow the same instructions and it keeps giving me the same error, also delete some files but nothing happens that I can do
You are running create-react-app 4.0.3, which is behind the latest release (5.0.0).
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/
update create-react-app with npm update -g create-react-app
if it still doesn't work try using one of these commands:-
npm init react-app my-app
create-react-app my-app
you might need sudo
sudo npm uninstall -g create-react-app
if this does not work get the path
which create-react-app
remove the directory
rm -rf /pathToCreateReactApp

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 bash: /usr/local/bin/create-react-app: No such file or directory

I had an origonal problem that I tried to fix and got another problem
1. ORIGONAL PROBLEM
I just tried to install a new react app using create-react-app and got this error first
Please note that global installs of create-react-app are no longer supported.
The node modules were installed but none of the other files or directories that normally install.
2. What I did to fix Origonal problem
on the react app website it https://create-react-app.dev/docs/getting-started/ it was suggested that I do the following (which I did)
"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."
I tried to run the command npm uninstall -g create-react-app but could not do it as my mac prevented it so ran sudo npm uninstall -g create-react-app
3. New PROBLEM
When I now run create-react-app I get the message
bash: /usr/local/bin/create-react-app: No such file or directory
TDI-MacBook-Air:Active bob$
What do I need to do to get create react App back. I am worried about messing up my installation more so am hesitant to go at it without some advice
Just simply run npx create-react-app app_name to create your app.
npx will fetch the latest version of create-react-app and setup your app.
This solved my error Just simply run npx create-react-app app_name to create your app. npx will fetch the latest version of create-react-app and setup your app.

How to fix: Npx create-react-app does not install everything only package.json and node modules

I'm trying to create a new react app, but whenever I do npx create-react-app or npm init react-app, only the node_modules and a portion of package.json is installed.
npx create-react-app new-app
(https://imgur.com/iJDVQ3E) -> Current package.json and folder structure
Expected public folder and script run commands in package.json
I know it's been two months, but I came across this exact issue and found the next solution:
You only need to update your npm and node modules, they are outdated for us or missing something important and that is why we get no template folders. Try below command:
run npm install -g update-node
run npm update npm -g
These two commands should fix it, if not, let me know, maybe I forgot one command to tell you.
Uninstall react in case its installed globally by running the command "npm uninstall -g create-react-app". then run "npx install -g create-react-app".
npx comes with npm 52+ updated versions
tried using the above 2 commands and got created all the required folders under react app.
run npm install -g update-node
run npm update npm -g

Create React App not working

Help! I have no idea what is going on here, create react app is not working I have also tried reinstalling and yet to no avail, please help!
Npm version: 5.4.2
Node version: 8.70
Tried the npm install --save --save-exact --loglevel error react react-dom react-scripts
In my case, "create-react-app" was not installed. to install run this command
npm install -g create-react-app
Once installation successful, try running
npx create-react-app hello-world
If this works for you. Great else comment what worked for you,
Please try this:
npm cache clean --force
I also got the same issue and tried to resolve for a long and finally resolved using this command,
npx create-react-app#latest my-app --use-npm
I had the same problem and had to do the following:
npm uninstall -g create-react-app
npm uninstall create-react-app
After this I was able to create the app with:
npx create-react-app project-app
I had the same problem, and I solved it by:
1. update the npm version (npm install npm#latest -g)
2. clear the cache (npm cache clean --force)
3. create the react project (npx create-react-app todo)
(create-react-app was already installed)
I had similar issue while tried creating new react app with create-react-app, but related to some random JSON reading issues while installations like.. >= 5.0 || 4.0 ..
But the fix below solves multiple and similar issues.
First of all, make sure you have required or latest version of node installed.
npm install npm#latest -g
Before using create-react-app make sure you clean npm cache using npm cache clean --force
Now, is should be fine to create new react app with npx create-react-app tl-app or npx create-react-app . if you want to create current directory as project root.
Make sure you are not running any antivirus, stop/pause all antivirus or protection software.
You can also try
use create-react-app projectname --save
or create-react-app projectname --save-exact and start again
OR
as the error suggests, you should use a newer version of node. You are using 8.9.4, you should probably use 8.12.0 LTS.
It sets up your development environment so that you can use the latest JavaScript features, provides a nice developer experience, and optimizes your app for production.
You’ll need to have Node >= 8.10 and npm >= 5.6 on your machine. To create a project, run:
npx create-react-app my-app
cd my-app
npm start
Note:
npx on the first line is not a typo — it’s a package runner tool that comes with npm 5.2+.
Create react app provides more information regarding this.
It may be the problem of cache also, so can also try:
npm cache clean --force
Edit 1: This may be due to slow internet speed, Please check the
internet and try again.
npx create-react-app .
( the .) means create project on this folder so you should manually create if you do that
For the windows machine following command worked for me
yarn create react-app my-app
cd my-app
yarn set version berry
yarn
yarn start
The problem on my machine was caused by yarn. I am windows 10 and after uninstalling yarn using npm uninstall -g yarn, my script run correctly. So
Open terminal and type: npm uninstall -g yarn
Once done, close terminal and open new one
type create-react-app (app name) and this should create your app :)
Please note that the above steps assume that you already have node and react-cli installed on your machine.
on Ubuntu 18.04
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
What I did, is going to
C:\Users\mycomputerName\AppData\Roaming\npm\
I changed the name of this file
create-react-app.ps1
to
create-react-appOld.ps1
or you can delete it, then it worked fine
Tried all the above methods but no luck:(
Step1 : Reinstalled Node js
Step2 : Check whether environment variables has been created. if not create one for nodejs,npm and composer
Step3: Also add "C:\Windows\System32" to the global PATH environment variable.
Step4: Then use "npx create-react-app my-app" to create react project
Step5: Run the commmand : cd my-app and npm start
Step6: It will work
I finally got it to work. An anti-virus in my system was causing it not to work property. I unistalled it and it's working as expected.
After no luck with updating my npm version and doing npm cache clean --force I ended up just doing a fresh install of node which fixed the issue for me.
HAD the same problem. Running Node with cra. installed cra -g for starters.
npm install -g create-react-app
then downgraded react-scripts to version 2.1.8
npm install react-scripts#2.1.8
created a .env file in root directory and added this to it.
DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3
SKIP_PREFLIGHT_CHECK=true
Then you do the typical delete node_modules folder and the package-lock.json file.(NOT PACKAGE.JSON!!!)
then:
npm install
npm start
This worked for me. Sorry I'm not more informative on why this worked for me. I'm still trying to understand why it didn't work in the first place.
I just did it now after messing around with it all yesterday.
Installed react globally like people have said.
then I used 'git bash here' to open terminal in the directory i want
oddly, it worked when I removed npm. I know it's weird, I've never had to do that and it makes no sense but its working so:
create-react-app my-app-name
I'm on windows 10 by the way.
If there is anyone having this issue that you can not find your project when you
yarn create-react-app (name of project)
npx create-react-app (name of project)
then just be sure that you are in the right directory.
use this command in your terminal
cd ..
now search the project name by
cd (project name)
you should find your directory here.
Please do this, I hope it will fix all of your problems
1- npm i -g create-react-app
2- create-react-app my-app
Find the folder and where a folder named npm is present and add it into environment variables (path)
I also experienced the same problem and SOLVED IT.
This is what I did.
Restart your machine(computer)
Deactivate your anti-virus. I chose the "permanently" option
Open the terminal and run the "create-react-app" command again, It will definitely do the trick.
Activate your anti-virus
And get working :-)

Resources