I keep encountering the "command not found" error when trying to create a new react native project. I've looked through past questions on this topic and they all say to change the PATH, which doesn't seem to work for me.
I tried installing and uninstalling react-native-cli. I've checked and changed the PATH. Nothing works.
Davids-MBP-2:~ David$ brew -v
Homebrew >=1.7.1 (shallow or no git repository)
Homebrew/homebrew-core (no git repository)
Davids-MBP-2:~ David$ watchman -v
4.9.0
Davids-MBP-2:~ David$ node -v
v11.13.0
Davids-MBP-2:~ David$ npm install -g react-native-cli
/Users/David/.npm-global/bin/react-native -> /Users/David/.npm-global/lib/node_modules/react-native-cli/index.js
+ react-native-cli@2.0.1
updated 1 package in 1.392s
Davids-MBP-2:~ David$ react-native init hello
-bash: react-native: command not found
Davids-MBP-2:~ David$
I installed node, homebrew, watchman, and finally react-native. The first three work, but react doesn't.
You first to make you sure that /usr/local/share/npm/bin is in your PATH to use binaries installed with npm.
Add following are to your ~/.bashrc:
export PATH="/usr/local/share/npm/bin:$PATH"
you also sure about that path you install npm pakage.if that can not fullfill your requirement npm from bin then you must uninstall and after fully uninstall you install it again it may be work.It work in my case
I'll first describe the setup on my system.
Check first where brew install node
installed your node_modules
.
$ npm root -g
/usr/local/lib/node_modules
Next, check that the installed scripts/commands are in a corresponding bin folder:
$ ls -l /usr/local/bin | grep react-native
... react-native -> ../lib/node_modules/react-native-cli/index.js
Next, make sure that the bin folder is in your $PATH
.
$ echo $PATH
...:/usr/local/bin:...
Finally, persist the path to that bin folder by adding it to PATH
in your ~/.bash_profile .
$ cat ~/.bash_profile
...
export PATH=$PATH:/usr/local/bin
...
$ source ~/.bash_profile
(I am not sure if your Terminal env need you to do source ~/.bash_profile
every time you open a new Terminal session.)
Now, from your comment, it seems you have your node_modules installed in a non-standard folder.
this is the output of npm root -g: /Users/David/.npm-global/lib/node_modules
Try doing the same steps I mentioned above:
PATH
PATH
by putting it in your ~/.bash_profile . If you can't find the bin/react-native , try these:
$ find /Users/David/ -name "react-native" -type l
$ find /usr/local/bin -name "react-native" -type l
Those commands may take a long time, but it should return something like this:
$ find /usr/local/bin -name "react-native" -type l
/usr/local/bin/react-native
Once you've found the path to react-native
bin, it should just be a matter of adding it your PATH
and persisting it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.