Relative path in index.html after build

ReactjsBuildPathCreate React-AppReact Scripts

Reactjs Problem Overview


Hello i have a reactjs app, and I build my project with bellow command

npm build

Here is my package.json file:

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"},

after build i have folder with build files and index.html file But all paths in this .html are absolute, i want to build with relative path

for example (index.html): now i have:

>

i want this:

>

Reactjs Solutions


Solution 1 - Reactjs

// package.json
{
  "name": "your-project-name",
  "version": "0.1.0",
  "homepage": "./", # <--- Add this line ----
  ...
}

Run npm run build again.

This will change the path to ./, which is the relative path of your project.

Solution 2 - Reactjs

I encountered a similar issue and resolved it by setting "homepage": "./" in package.json

I found this solution here https://github.com/facebook/create-react-app/issues/165

Solution 3 - Reactjs

If you're using webpack, you can try setting publicPath to ./

You can read more about it here.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3045654View Question on Stackoverflow
Solution 1 - ReactjsGampeshView Answer on Stackoverflow
Solution 2 - ReactjsGanesanView Answer on Stackoverflow
Solution 3 - ReactjsMr. 14View Answer on Stackoverflow