close

[Solved] Can’t build create-react-app project with custom PUBLIC_URL

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Can’t build create-react-app project with custom PUBLIC_URL in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Can’t build create-react-app project with custom PUBLIC_URL Error Occurs?

Today I get the following error Can’t build create-react-app project with custom PUBLIC_URL in javascript.

How To Solve Can’t build create-react-app project with custom PUBLIC_URL Error ?

  1. How To Solve Can't build create-react-app project with custom PUBLIC_URL Error ?

    To Solve Can't build create-react-app project with custom PUBLIC_URL Error As documented here create-react-app will only import environment variables beginning with REACT_APP_, so the PUBLIC_URL, I believe, as mentioned by comes from the homepage setting in the package.json file.

  2. Can't build create-react-app project with custom PUBLIC_URL

    To Solve Can't build create-react-app project with custom PUBLIC_URL Error As documented here create-react-app will only import environment variables beginning with REACT_APP_, so the PUBLIC_URL, I believe, as mentioned by comes from the homepage setting in the package.json file.

Solution 1

If the other answers aren’t working for you, there’s also a homepage field in package.json. After running npm run build you should get a message like the following:

The project was built assuming it is hosted at the server root.
To override this, specify the homepage in your package.json.
For example, add this to build it for GitHub Pages:

  "homepage" : "http://myname.github.io/myapp",

You would just add it as one of the root fields in package.json, e.g.

{
  // ...
  "scripts": {
    // ...
  },
  "homepage": "https://example.com"
}

When it’s successfully set, either via homepage or PUBLIC_URL, you should instead get a message like this:

The project was built assuming it is hosted at https://example.com.
You can control this with the homepage field in your package.json.

Solution 2

As documented here create-react-app will only import environment variables beginning with REACT_APP_, so the PUBLIC_URL, I believe, as mentioned by comes from the homepage setting in the package.json file.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment