Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run create-react-app from sub-folder

I'm using create-react-app. I want to run my code from nested directory/sub-directory. My directory structure is as per the screenshot.

enter image description here

I'm using npm start command to run it localy.

I have update my package.json file like

"homepage": "/foobar/"

and my index file

ReactDOM.render(
    <Router basename={'foobar'}>
        <div id="wrapper">
            <RouteList />
        </div>
    </Router>,
    document.getElementById('root')
);

for the routing plugin - link I have included node_modules into both directory for the testing purpose.

but still I'm getting below error while trying to run npm start from the root directory.

Could not find a required file.
  Name: index.html
  Searched in: C:\git\AccountManager\public

It's working fine from the inner folder. Any idea on how to solve this?

like image 598
Dipen Dedania Avatar asked Nov 08 '25 04:11

Dipen Dedania


2 Answers

You could change directory to foobar first run npm start. I would incorporate that in my npm start command so that it now looks like the following:

package.json

{
  ...
  "scripts" : {
    "start": "cd foobar && react-scripts start",
    ...
  } 
}
like image 60
Mμ. Avatar answered Nov 11 '25 05:11

Mμ.


So far I managed to make it work only if I move only index.html to public folder in the root, or by installing all React node-modules under src folder

like image 22
Ursu Alexandr Avatar answered Nov 11 '25 06:11

Ursu Alexandr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!