question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create React App inside a non-empty folder

See original GitHub issue

I use create-react-app to create a react app inside an existing backend project which will serve the react application. And I have to run the eject command to:

  • change the target directory
  • change the build logic and directories
  • add .less support with some extra configuration and so on…

To automate this process, I took a fork from react-scripts and I defined my folder structure. A

My final file system hierarchy should be something like:

- project directory
    - foo
    - bar
    - baz
    - resources
        - react-app
            - index.js
    - package.json 
    - qux.php

So I edited the template folder to match these requirements and published the scripts to give a try.

npx create-react-app . --scripts-version my-react-scripts

And as you guessed, I got

The directory . contains files that could conflict: Backend FSH.

However:

  • I need my package.json to be located in the project root directory.
  • My scripts will create a new directory called react-app inside the existing resources folder. And react-app will live inside this directory. I don’t expect an override.
  • My build is customized and will use my webpack plugin to generate the built files. I don’t expect an unexpected override here as well.

Describe the solution you’d like

  • Since I know what I do, I want to have some way to run create-react-app in an existing folder with some files.

Maybe by setting a constant from my scripts or using an option after npx create-react-app call.

Describe alternatives you’ve considered

I considered to update create-react-app to support it as well but that doesn’t make sense since it would be almost impossible to follow up the updates and upgrades later.

Additional context

https://github.com/facebook/create-react-app/issues/334 https://github.com/facebook/create-react-app/issues/2776

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
erdemkerencommented, Oct 14, 2019

Hello, Thanks for your reply @JacobMGEvans!

Haha! That is one of my first shots as well 😃 I also considered working with:

  • .git
  • back-end
  • front-end

But:

  • I use npm run development -- --watch to watch the changes of the file system and move the generated/built:
    • index.html as root/resources/views/app.blade.php
    • robots.txt and *.js and other static assets as public/robots.txt, public/*.js, public/assets/*.js.
    • single page app
    • single page page-components (like 403, 404, 500) as … so on.

All of them programmatically and on every save (backend serves the output).

If I include the package.json inside root/React, then my watch and build commands will write the output to a higher level then the package.json and that doesn’t make sense to me. I really feel like it belongs to the whole project since it affects a lot of places out of the React directory in the suggested example.

That is why It makes perfect sense to move the configuration to the root directory. I hope it makes sense to you too.

Having rmdir is great but I am looking for rm -rf at the moment =)

0reactions
JacobMGEvanscommented, Oct 14, 2019

I see. I think what you are doing is exactly why the eject is available to “own” the configurations. I would definitely be interested in what the maintainers have to say. Pretty slick that you got that to work though!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a React app directly in the current folder
First go to the directory where you want to create react app. · Then run the command npx create-react-app .
Read more >
React-Scripts from an empty directory | by Srecko Kostic
We will set up everything from an empty directory using react-scripts. The react-scripts support up to medium-sized projects.
Read more >
React | IntelliJ IDEA Documentation - JetBrains
When creating an application, select the folder where the create-react-app package is stored. Optionally: To use TSX instead of JSX, select the ...
Read more >
How to Create a React Project & Directory Explained - YouTube
Learn how to setup your first React project & see what files are being added from scratch – Learn one of the most...
Read more >
create-react-app React File Structure - Pluralsight
While components can reside in src/components/my-component-name, it is recommended to have an index.js inside that directory. Thus, whenever ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found