4

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?

2 Answers 2

3

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",
    ...
  } 
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. but I wanna run it from the parent directory.
Just to be clear the root directory is the folder AccountManager right? Which also contains your package.json?
Correct. Package.json is only available in root.
So if you change the npm start in package.json to cd foobar && react-scripts start, when you run npm run start it should start the react app successfully.
1

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.