2

I am using create-react-app command to create an empty app, I got these file in src folder:

App.css
App.js
App.test.js
index.css
index.js
logo.svg
serviceWorker.js
setupTests.js

After I make a build via npm run build, index.html is generated in build folder.

I created one manually in src folder, but the build doesn't take it.

The index.js content is:

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

There is no root element at all.

I need to add in some <script> tag inside index.html to include some third party scripts (which cannot be installed by nodejs), where can I add them since it is not existed in src folder?

2
  • 2
    It's usually under public folder Commented Sep 3, 2020 at 6:20
  • @MorKadosh you are right! really out of expectation... Commented Sep 3, 2020 at 6:23

2 Answers 2

9

You have to check public folder in the root directory only. You will get your index.html would be there. and your index.js file which is in src folder is the single point of connection between them(main index.html in public folder and all Javascript code which is in src folder). enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

You are right, my bad, thought everything is in src folder.
1

You should download that third party lybrairie and put it inside of the public directory and include a script tag inside of the index.html file which is inside of the public directory of your project.

The configuration of the create-react-app is using webpack which is preconfigure to load the public\index.html file as the template in which the compiled bundle will be injected.

If you want to use the index.html file which you have create inside of the src folder you should run npm run eject which will put all create-react-app configuration at your disposal in your project directory and you could perform changes to webpack figuration file to load src/index.html file as the template in which the compiled bundle will be injected.

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.