create-react-app, installation error ("command not found") - node.js

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

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

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.

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

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

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.

Use npx instead of npm.
Check this out-> https://reactjs.org/docs/create-a-new-react-app.html#create-react-app

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

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.

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.

If above answers are not working, then try this
update the npm version (npm install npm#latest -g)
clear the cache (npm cache clean --force)
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)

This is how I get it fixed.
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
Step # 2:- Clean your npm cache by following the command
npm cache clean --force
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

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.

I faced a similar challenge but on running the command
npm i tar
I was able to resolve the issue.

Related

npm install not working. Says that I need to check permissions?

I'm trying to install eslint on my machine right now but it is saying that I need to check permissions because its missing write access to /user/local/lib/node_modules. Does anyone know how to fix this? Thanks!
npm install -g eslint
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
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 (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mkaplan/.npm/_logs/2019-03-03T18_05_46_487Z-debug.log
Try sudo npm install -g eslint
For Linux use sudo npm install and
For Window run powerShell as administrator and got to directory of project and run npm install
In my case I had this same problem to install angular, so just change the command to :
$ sudo npm install -g #angular/cli
This kind of stuff happens when you run npm commands with sudo to begin with. So don't do it?
If this happens, it means that someone has been messing around npm as root. Then root took and created files in global npm cache, denying access to anything different than root.
This is why it fires EACCES when running npm install or npm install -g
You are not supposed to do anything related to node_modules nor runnpm [anything] with sudo. Do you understand that you are giving the package in question permission to do whatever it wants? Even if you check the package and ensure its security yourself, what about dependencies it downloads? will you check them as well?
npm registry gets 30b weekly downloads, their malware control is nowhere near enough
You are giving away access to whole sys folder tree to the files of the package in question. Even npm itself gives you feedback that it is not recommended. You do not know what package does in the background. What if you install a package i developed, but i am a villian who likes to make people's life harder... This is a security issue.
The above story apart. If you do it with sudo, this will force you to run certain npm commands as sudo from that point on, messing it up even more.
The maximum you do as root in this case, is give access for node_modules to whoami
The best solution is to either set it up properly so you dont have to use sudo or run app in container, so anything you do is executed inside container, not affecting your local machine at least. Even there it is not recommended to mess around as root, permissions get so messy... it's a hell to debug.
I'm fairly new to Node but as a longtime Linux user I'not sure installing node packages as root (via sudo) is a good idea.
I imagine eslint is fine but if you're having this issue installing one package then I'm guessing you're having the same problem with every package you're installing globally ('-g'). That means that every time you install a package from npm globally you're downloading who-knows-what install script and running it with root privileges on your computer.
Anyway, as I said I'm no Node expert but I had this same problem and my issue was that I'd installed the "nodejs" package using apt. If this is what you did then I suggest:
Remove nodejs with sudo apt remove nodejs. (Depending on what Linux distro you're using this may be different. I'm running Ubuntu.)
Install nvm or some other node version manager as recommended by the NPM docs.
When I did this, I was able to install NPM packages globally without sudo.
(Yes, I'm telling you not to install things by running npm as root and then saying you should install things by running apt as root. But you definitely need to run apt as root and I know appropriate precautions are taken by the apt devs and Ubuntu package repo managers. I'm not 100% sure it's wrong to run npm as root but I'm not sure it's right either, and I was able to avoid running it as root using the above steps.)
This can solve the problem:
sudo npm install -g npm
First try sudo npm install -g gatsby-cli
then npm start
I ran into an issue trying to install truffle and got the following errors:
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
I was able to solve this issue with the recommendation to add 'sudo'.
solution:
sudo npm i -g truffle
Use the command:
sudo npm install -g eslint
With the sudo command you will have the permission to install.
This might happen when you just "sudo" everything in order to make it work or you install a dependency forcefully , you should not mess with the root folder of node modules.
For now you can try installing using
sudo npm install -g eslint
Use this npm install node-sass --save

npm is not updated in mac

I am using ios and installed npm few days back. Its current version is 5.6.0. Now, I want to update npm.
I am using the following steps to update npm:
I opened the terminal, wrote npm -v into terminal and looked into the current version of npm with is 5.6.0 as for now.
Then, I wrote npm update -g in terminal to update the current version of npm but it is showing the following error:
npm ERR! path /usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri
I had the same prob,
Go to your root
Run which npm and see the root, I believe it will be "/usr/local/bin/npm"
Stay on your root and try to run npm install -g npm#latest
I bet you get "missing permissions..."
Stay on your root and run the command: (to give permissions) sudo chown -R $USER /usr/local/lib/node_modules
And then run: npm install -g npm#latest
Now it should work, please try to run npm -v and see if it changed.
Goodluck :)

npm install puppeteer showing permission denied errors

I'm unable to install puppeteer as a project dependency, and I've tried re-installing node. Anyone have an idea on how to fix this? Running Ubuntu 17.10 x64
sudo apt-get purge nodejs;
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -;
apt-get install -y nodejs;
sudo npm install -g n;
sudo n stable;
Node versions:
$ node -v
v9.4.0
$ npm -v
5.6.0
I try to install:
root#server:/var/www/html# npm install --save puppeteer
Error message:
> puppeteer#1.1.0 install /var/www/html/node_modules/puppeteer
> node install.js
ERROR: Failed to download Chromium r536395! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/var/www/html/node_modules/puppeteer/.local-chromium'
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/var/www/html/node_modules/puppeteer/.local-chromium' }
npm WARN project#1.0.0 No description
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer#1.1.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puppeteer#1.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-02-19T15_55_52_669Z-debug.log
I don't see any ways to fix this in the referenced issue: https://github.com/GoogleChrome/puppeteer/issues/375
EDIT 20th April 2019:
The easy solution suggested by lauraalvarezz1 is,
sudo npm install -g puppeteer --unsafe-perm=true
This is okay as long as you trust puppeteer and want it to install puppeteer globally.
However beware of using --unsafe-perm=true for permission related problems. Reasons are:
Running unsafe-perm=true with sudo, as a non-root user, will give the script root access. This might be okay only if you trust the script and do not concern about security that much.
You might need to use --no-sandbox in every script you run, because the chrome installed with this command might not run without this parameter. See this github issue.
You have installed npm with sudo. Thus anything you install globally will require sudo.
To install anything on var/www/html folder, either you have to own that folder,
sudo chown -R $USER /var/www/html
Or you can use nvm to manage npm. Technically it will use your home directory and your current user.
After installing nvm, you can install puppeteer globally with it,
npm i -g puppeteer
or you have to use sudo
sudo npm install --save puppeteer
However chromium will not be downloaded due to permission error, that's why you have to use ---unsafe-perm=true as stated before.
Security Related Resources:
Resolve this without sudo, you can use this answer.
Learn more about best practices dealing with /var/www folder, refer to this answer.
Best of luck!
Run this on your terminal:
sudo npm install -g puppeteer --unsafe-perm=true
Before you begin, make sure you have the most recent version of Node.js.
The Puppeteer Documentation states:
Note: Puppeteer requires at least Node v6.4.0, but the examples below use async/await which is only supported in Node v7.6.0 or greater.
You can check which version of Node.js you have using the following command:
node -v
# OR nodejs -v
If your version of Node.js is less then v7.6.0, you can completely uninstall your current version of Node.js.
Then, you can use complete the reinstallation using a PPA:
sudo apt update
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
sudo apt install build-essential
You can check the new versions of Node.js and NPM installed on your system:
node -v
npm -v
Finally, you can install Puppeteer:
sudo npm install puppeteer --unsafe-perm=true --allow-root
Now you can run Puppeteer scripts using the node command:
node puppeteer-script.js
I did:
yarn install --ignore-scripts
yarn install.
And it worked without sudo or global package installation.
It should work with npm too.
I have Ubuntu 20.04.

Installing npm package fails with 404

Using the command prompt, I am trying to install angular CLI and it fails. I have npm version 5.5.1 and node version v8.9.1. I am trying to install angular cli using the command
npm install -g #angular/cli#latest
and it fails with the error:
npm ERR! code E404
npm ERR! 404 Not Found: #angular/cli#latest
npm ERR! A complete log of this run can be found in:
I look at the log file and I see its trying to fetch the package from a location that doesn't exist. Not sure from where it gets pulled. How do I fix this location path and install angular cli. Same happens when I try to install typescript or any other npm package. all of them try to install from the location mentioned below and it fails with 404
8 http fetch GET 404
http://nuget.feed.xyz.corp:8729/npm/FeedNPM/#angular%2fcli 109ms
9 silly fetchPackageMetaData error for #angular/cli#latest 404 Not Found:
#angular/cli#latest
10 verbose stack Error: 404 Not Found: #angular/cli#latest
npm config set registry http://registry.npmjs.org
NPM registry documentation
Try first this commands (in windows run as administrator)
npm config set registry http://registry.npmjs.org
npm install -g #angular/cli
if still not working let's update NPM and nodejs by running this commands
npm -g install npm
npm cache clean -f
npm install -g n
then try to run
npm install -g #angular/cli
This should solve this problem
in my case it was .npmrc file in my project dir, which kept overwriting my global registry url. As soon as I deleted it, I could finally use npm install
Add a .npmrc file in the root of the project. .npmrc will look like below -
#xy:registry=https://xyz.jfrog.io/xyz/api/npm/npm-local/
#xy-app:registry=https://xyz.jfrog.io/xyz/api/npm/npm-local/
And Delete all the field eg - email , auth etc.
Find out what is the registry url of your application and put it into the registry.
Then run command - npm install
And it will work.
It was giving the same error for me when I use office network/vpn as they have 'umbrella' DNS security shield. To solve this issue, connect to personal network and type the below commands:
npm config set registry http://registry.npmjs.org
npm install -g #angular/cli
Alternative, another option to avoid 404 npm error
check if your terminal is in the root directory, if not your npm scripts will not execute
because it will not be able to see the package.json
I had same problem with a private package.
Need to:
npm adduser
npm login
I spent hours on this.
I had to follow the below steps to get it to work (mac).
Delete my LOCAL (not project) .npmrc by running:
rm /Users/<NAME>/.npmrc
Then set the registry:
npm config set registry https://registry.npmjs.org/
Then follow the steps for logging in to npm:
npm login
Check what's in your config list by running:
npm config list
It should look like this:
//registry.npmjs.org/:_authToken = (protected)
registry = "https://registry.npmjs.org/"
Hope it works for you too.
change your access level to public. type this in the terminal
npm --access=public
install your angular.
sudo npm install #ngular/cli
In my case, that's a typo error:
change trct-js-sdk to trtc-js-sdk saved my life.
My solution was as follows because I had a dependency on a private package. If you see the dependency in package.json defined in the format #scope/package, then #scope tells you that it's a scoped package that might be private.
Get the private package owner to grant you access to the package
Upgrade npm
Upgrade node
Add registry using HTTPS (not HTTP), e.g. npm config set registry https://registry.npmjs.org
Do "npm login"
Now run the build
Uninstall NPM & nodejs and install the right way NPM (Ubuntu)
sudo with npm is not recommended
To Uninstall
sudo apt-get remove nodejs
sudo apt-get remove npm
or
sudo apt-get purge nodejs
Followed by proper installation
curl -o-
https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
To confirm open a new terminal run:
$ command -v nvm
Latest LTS release of NodeJS:
$ nvm install --lts
Set default environment
$ nvm alias default lts/*
Worked for me
I got
error 404 'dotnev#*' is not in this registry.
Deleted .npmrc file in 2 folders back over my project root
and then in the project root folder typed:
npm i dotenv
copied from:
https://www.npmjs.com/package/dotenv
Just run sudo npm config set registry http://registry.npmjs.org and then update your npm.
It is an network error , check your network connection and try to install it again.
the only command line "npm -g install npm" solved the issue for me!
the following link can be helpful to dig deep for a better understanding.
Thanks a lot.

React native keeps requesting react-native-cli to be installed globally

Here are the steps I did to set up my project:
$ git clone ssh:<project>
$ cd <project>
$ nvm install 5.0
$ nvm use 5.0
I then check my node version and it appears to be correct: v5.0.0.
$ npm install
$ npm install -g react-native-cli
This all seems to go according to plan, and locally, it gives me a tree with all the correct dependencies.
When I do npm list --depth=0 -g, I get expected results.
├── npm#3.3.6
└── react-native-cli#1.0.0
So I try to run the npm start script, which is react-native start. However, whenever I try to run it, I get the following basic error:
Looks like you installed react-native globally, maybe you meant react-native-cli?
To fix the issue, run:
npm uninstall -g react-native
npm install -g react-native-cli
I've tried just about everything I can think of, down to uninstalling node and nvm completely and starting from scratch.
What is the solution to this problem?
This upcoming error message is not very helpful. Besides your npm installation issue I found also an npm start doesn't work after upgrade to 0.15.0 bugfixing issue with the same error message.
First of all you should check the symbolic link shown after npm install:
$ npm install -g react-native-cli
/usr/local/bin/react-native -> /usr/local/lib/node_modules/react-native-cli/index.js
Check if the linked file exists:
ls /usr/local/lib/node_modules/react-native-cli/index.js
If not, check your npm path settings with
npm config list
or directly in ~/.npmrc
In my case I had a wrong prefix in ~/.npmrc, which I've deleted completely. As the npm ERR! message shows after another npm install -g react-native-cli, it came up with:
npm ERR! Refusing to delete /usr/local/bin/react-native: ../lib/node_modules/react-native/local-cli/wrong-react-native.js symlink target is not controlled by npm /usr/local
npm ERR! File exists: /usr/local/bin/react-native
npm ERR! Move it away, and try again.
Look at the indicated 'wrong-react-native.js' filename at the end.
Delete that link, do a npm update and try npm install -g react-native-cli again.
Worked on MacOS X. npm installed with homebrew

Resources