39

I have installed create-react-app exactly as instructed on the facebook instruction page (https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html):

First, install the global package:

npm install -g create-react-app

I did this. It appeared to work fine - the file was installed to

users/*name*/.node_modules_global/lib/node_modules/create-react-app

I'm not really sure why global install takes it to this path, but there you have it.

Next instruction:

Now you can use it to create a new app:

create-react-app hello-world

Couldn't be simpler, right? But Terminal spits out this at me:

-bash: create-react-app: command not found

It's probably something very simple I'm missing but I don't really know where to look. If anyone can help I'd really appreciate it!

Thanks in advance.

Note: I'm using Node v6.3.1, and npm v3.10.3

Paulos3000
  • 2,717
  • 7
  • 30
  • 63

11 Answers11

57

You are able to apply the following solution:

$ npm config set prefix /usr/local
$ sudo npm install -g create-react-app
$ create-react-app my-app
Hamdi Bayhan
  • 1,483
  • 4
  • 15
  • 20
  • 1
    This is helpful, using yarn, yarn config set prefix /usr/local sudo yarn global add create-react-app – Apetu Gideon Sep 25 '19 at 18:51
  • I dont get why set a prefix to on npm will fix the pointing issue. where is prefix to be set on ? – Fenici Feb 11 '20 at 13:28
  • Windows users beware: running `npm config set prefix /usr/local` might wreak havoc on your console, and you could end up with an `Error: EPERM: operation not permitted` error that will require you to follow [this guide](https://stackoverflow.com/questions/34600932/npm-eperm-operation-not-permitted-on-windows) – I_Literally_Cannot Sep 30 '20 at 06:44
  • Thank you works for me on macOs Catalina – Pravin Waychal Dec 15 '20 at 04:43
  • this is works on Big Sur. ( 11.2.1 (20D74) ) Thank you. – alpertayfun Feb 24 '21 at 07:41
23

Your Node setup looks incorrect. It's not an issue with Create React App—it seems like you can't run any global Node commands.

It looks like ~/.node_modules_global/bin is not in your PATH environment variable so it can't execute global commands. That's just how Bash works—it can't guess where the command lies, you need to tell it. I would assume Node installation should do this by default but it depends on how you installed Node.

So make sure that directory is in your PATH and try again. If you use Bash, add this to your .profile and then restart the Terminal:

export PATH=$HOME/.node_modules_global/bin:$PATH
Dan Abramov
  • 241,321
  • 75
  • 389
  • 492
  • FIxed! Thanks, that was just what I was after. Although there shouldn't be quotation marks around the filepath :) – Paulos3000 Aug 03 '16 at 20:58
  • Thanks for clarification! – Dan Abramov Aug 03 '16 at 23:10
  • Sorry, just one more question: although this worked, when I quit Terminal I have to repeat the process every time I reboot it. Is there a way of permanently changing the $PATH? – Paulos3000 Aug 04 '16 at 18:19
  • I don't intend to be *that guy*, but what if you don't want to install globally? I know this is the custom in Node, but whatever. Can you point at the `.node_modules` directory _within_ your project? Coming from Ruby, installing things so that they are available everywhere feels slightly _verboten_. – Chris Sep 02 '16 at 02:33
  • You don't need it in the future to be globally to *run* that project. The thing that created projects depends on *is* inside local `node_modules`. Your team members don't need to install CRA itself. – Dan Abramov Sep 11 '16 at 19:24
  • Installing it globally is fine because it almost never changes. There won't be dependency hell or anything because no projects will depend on it. It's just a command that creates a folder and runs npm install in it, letting a locally installed script take over. But if you insist on using zero global commands, yes, you can install CRA in some folder and run `node ./node_modules/.bin/create-react-app myapp` in that folder. It seems unnecessary though so I recommend against it. – Dan Abramov Sep 11 '16 at 19:26
  • @Paulos3000 Did my suggestion of putting it into `.profile` in your home directory work? That should execute when your Terminal starts. – Dan Abramov Sep 11 '16 at 19:28
  • Hi Dan, sorry I didn't manage to get that to work. It works when I do it temporarily - `export PATH=$HOME/.node_modules_global/bin:$PATH` - but I don't know how to access `.profile` through Terminal in order to make a permanent change to `$PATH`... can you help with this? – Paulos3000 Sep 11 '16 at 20:31
  • With my setup i.e Windows 10, Node v 6.7.0 , npm v 3.10.0, I could not find .node_modules_global folder. However the executable create-react-app command was located under `\Users\\AppData\Roaming\npm` folder and adding it to system path variable worked for me. – M.A.Naseer Oct 14 '16 at 16:29
  • In order to get node bin path use following command:"npm config get prefix" – JainAnk Dec 02 '16 at 18:57
  • Worked for `create-react-native-app` too – xilef May 02 '19 at 15:18
21

The environment variables are not set properly. When you run the create-react-app it shows you a path along with the error. Copy that path and add it in the environment variable.

Alternatively you can use the command:

npx create-react-app <app_name>.

This will do the work for you.

Stephen Rauch
  • 40,722
  • 30
  • 82
  • 105
Monil Bansal
  • 219
  • 2
  • 4
7

Try this. It worked or me. I found this in the React documentation. "Npx" is not a typo. It's a package runner tool that comes with npm 5.2+.

npx create-react-app my-app

Michael Neely
  • 141
  • 2
  • 4
4

Use npx instead of npm.

Check this out-> https://reactjs.org/docs/create-a-new-react-app.html#create-react-app

ssareen
  • 107
  • 3
3

Answers given above are right but I want to share some things that I also faced and these are basics.

To setup react project

If you want to create a node environment

$ sudo apt-get update
$ sudo apt-get install nodejs

(Sometimes we can also run without sudo; but sudo means install in system level.)

$ sudo apt-get install nodeenv

$ nodeenv env
$ source /bin/activate

If you want to create new react app then

$ npm install create-react-app

If an error occurs create-react-app: command not found then install with -g, it happens because node is installed globally and it is not getting the node in local

$ npm install -g create-react-app

$ create-react-app app_name
$ cd app_name
app_name$ npm start
tripleee
  • 139,311
  • 24
  • 207
  • 268
Vinay Kumar
  • 849
  • 8
  • 14
3

In 2020 Dec 17

Install Nodejs & npm

sudo apt update
sudo apt install nodejs
sudo apt install npm

if you install maybe show you this like errors for Reactjs setup.this helpful for you

npm install -g create-react-app


npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/create-react-app'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2020-12-17T14_16_02_442Z-debug.log

then When you type after this

create-react-app test-react-app 

Show you in terminal zsh: command not found: create-react-app

you fix this error by using this command

sudo npm install -g create-react-app
create-react-app test-react-app

I hope work fine for you also.

Kashif
  • 742
  • 7
  • 13
1

I hope you already installed Node package manager(npm). now run npm install -g create-react-app, if everything fine then you can use create-ract-app command. if you are getting any permission error just sudo npm install -g create-react-app.

I hope it will work. Happy Hacking.

Uddesh Jain
  • 541
  • 1
  • 9
  • 14
1

I tried all methods listed above and in other sites. They weren't working for me. But for some reason I decided to add the create-react-app directory into my system variables as a last ditch method and to my surprise this actually worked.

m02ph3u5
  • 2,735
  • 6
  • 34
  • 45
1

if you face following this problem:

create-react-app: command not found

solution:

  sudo npx create-react-app react_spa
  cd react_spa
  sudo npm start

I hope its work.

0

If above answers are not working, then try this

  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 myapp) (while running the 3rd command, make sure that create-react-app is already installed in the pc)