3
votes

I have been going through the react-native tutorial and ran

react-native init AwesomeApp as detailed in the FB page.

After many trials and errors in setting the correct permissions and path I was able to get the app running on IOS.

Awesome app is in a directory Projects

Now I want to create my own app in the same Projects folder and when I try

react-native init newApp I get

 Looks like React Native project already exists in the current
 folder. Run this command from a different folder or remove          node_modules/react-native

I tried from a different folder and still get the same message.

What's the best way to resolve this, deleting the node_modules/react-native or is there another solution and why the same error in a different folder?

6

6 Answers

3
votes

Had the same issue, the solution wasn't obvious and I find it nowhere on the Internet so I'm leaving it here.

You may have installed react-native globally. While you should install react-native-cli globally.

Having the first one installed makes typical react-native commads work (starting an app, linking native modules). The only difference is that init fails with above message. And IIRC calling react-native without arguments reveals the source of the problem with descriptive message that you've globally installed wrong package.

Edit: On Windows also make sure to use CMD, not PowerShell. PowerShell was calling react-native binary (instead of react-native-cli) from SOMEWHERE (I don't know the source, I don't have it available globally, I removed every single globally installed package and it was still calling it (probably from some locally insalled copy)). React Native development caused another issues too (can't remember the details, sorry) when used with Powershell, so just stick to CMD on Windows.

0
votes

You were probably still in the AwesomeApp directory while running react-native init newApp.

Try cd .. back to the Projects directory and run react-native init newApp again.

You will then see newApp directory is created inside the Projects directory.

0
votes

This error occurs when it is in a folder that you deleted. Try to cd to another folder, and it will work.

0
votes

In the directory C:\\Users\YourUserName you have a file "nodemodules" and a file named "MyProjectName" .

you should delete nodemodules file.

it works for me!

0
votes

I ran into this too, Make sure your folder does not have any node modules, if problem persists then install react-native-cli again globally using yarn add global react-native-cli and then initialize your project. using react-native init {name}.

0
votes

I had the same error because in some parent directory was backuped "node_modules" directory. Error resolved by rename it.