61

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!

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

14 Answers 14

80

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
Sign up to request clarification or add additional context in comments.

5 Comments

This is helpful, using yarn, yarn config set prefix /usr/local sudo yarn global add create-react-app
I dont get why set a prefix to on npm will fix the pointing issue. where is prefix to be set on ?
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
this is works on Big Sur. ( 11.2.1 (20D74) ) Thank you.
this broke my settings. I believe my npm is installed locally. Naturally doing the 1st command breaks things.....how do I return to my default setting? please consider me a newbie - especially dealiing with configs and all. thanks
40

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>

Comments

26

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

10 Comments

FIxed! Thanks, that was just what I was after. Although there shouldn't be quotation marks around the filepath :)
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?
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.
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.
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.
|
12

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

npx create-react-app my-app

Comments

6

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:

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

Comments

5

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

Comments

4

Use npx instead of npm.

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

Comments

2

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)

Comments

2

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

Comments

2

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.

Comments

2

This is how I get it fixed.

  1. Step # 1:- Make sure, Node js and React js is installed globally. You can check Nodejs by node --version . If not installed, install and run export PATH=$HOME/.node_modules_global/bin:$PATH
  2. Step # 2:- Clean your npm cache by following the command npm cache clean --force
  3. run sudo npx create-react-app your-app-name

And that's it. you're done.

Please note, This solution worked for me for MAC OS

Comments

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.

Comments

0

Here is the Documentation https://create-react-app.dev/docs/getting-started/

  • Update Node & NPM

  • npm init react-app my-app or npx create-react-app my-app

  • cd my-app

  • npm start

Comments

-1

Note: use npx instead of npm.

Wrong Command: npm install -g create-react-app <app_name>

Correct Command: npx install -g create-react-app <app_name>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.