27

I have a folder setup with some files I already want to have in the folder. I want to be able to run

react-native init PROJECTNAME

and instead of creating a folder PROJECTNAME it would init a react-native project in the folder I am currently in.

Is this possible?


Currently, I have my setup already created from previous projects that I enjoy using (packages.json, config files, etc). I delete the node_modules, and then react-native init PROJECTNAME. Then I take the PROJECTNAME/ios PROJECTNAME/android folders generated within that folder, move them into the main project folder and it works pretty smoothly. Just not optimal.

3
  • I'm also creating the project and manually moving the files. If you already had a build then I found I also needed to clear the cache ./node_modules/react-native/packager/packager.sh clean
    – agtb
    Commented Oct 13, 2016 at 10:01
  • 1
    would be nice to make a script out of this, or nice if react-native could update their cmd line to accept this setup :) Commented Oct 15, 2016 at 13:01
  • 1
    Yep, especially if you created the repo first. Commented Mar 4, 2017 at 2:48

5 Answers 5

31

You can do

$ cd .. && react-native init folder_name

It will overwrite your package.json but keep the non-default files.

3
  • 1
    Will this not overwrite the entire folder? Commented Apr 20, 2017 at 13:37
  • 1
    Only the files it needs to.
    – Viktor Sec
    Commented Apr 20, 2017 at 15:52
  • 2
    This is the code to copy the folder name, drop down a level and init into it. result=${PWD##*/} && cd .. && react-native init $result just be sure to only use alphanumeric characters and underscores in folder names or react native will reject it. This assumes you start in the folder you want to init.
    – chaiboy
    Commented Oct 31, 2018 at 21:01
5

You should have install react-native-cli instead of react-native globally as described here.

And then the command is:

npx react-native-cli init appname --directory ./appPathToDir

2

This issue is currently tracked there.

1
  • 1
    Already working Commented Aug 9, 2023 at 19:02
1

The reason I wanted to do this was to have a sort of mono-repo, but I have transitioned away from this approach as I am not sure it is beneficial.

-1

expo init /.

this will create expo app in current directory using the folder name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.