create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

PUBLIC_URL is not the same as homepage, but only the pathname

Open elvisLAI opened this issue 5 years ago • 22 comments
trafficstars

Describe the bug

I have uploaded all the static resources to CDN, include .js and .css files. So I have to set the 'homepage' as the host address of CDN server, which make the urls of scripts in 'index.html' to be right.

However, the urls injected to 'index.html' is the pathname of 'homepage' that I set in package.json, after upload react-scripts to 3.4.1.

And there is no such problem when I using version 3.3.0. I found that the actual homepage has been change after this PR feat(react-scripts): allow PUBLIC_URL in develoment mode

So I want to know, is it a bug that will be fixed? Or is there any method that can make the PUBLIC_URL to be a complete url.

Did you try recovering your dependencies?

no, but downgrade to 3.3.0

Which terms did you search for in User Guide?

The docs still use the complete url as example Step 1: Add homepage to package.json

Environment

irrelevant, i guess

Steps to reproduce

(Write your steps here:)

  1. set homepage in package.json like 'https://example.com/a/b/c'
  2. yarn build
  3. the url of script in index.html will be '/a/b/c/xxx.js', which will not find the correct resource

Expected behavior

The PUBLIC_URL should be the same as homepage in package.json

Actual behavior

The PUBLIC_URL is the pathname of homepage

Reproducible demo

no demo

elvisLAI avatar Apr 09 '20 13:04 elvisLAI

Does anyone have a fix for this other than changing version to [email protected]? I changed the version and it created an issue as follows: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

Found the fix. Changed react-dev-utils to 10.1.0

Gcolon021 avatar Apr 21 '20 13:04 Gcolon021

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar May 22 '20 06:05 stale[bot]

Bumping this to prevent the stalebot from closing it. This is still a relevant issue. #7259 accidentally introduced a breaking change into v3.4.0

anthem-bmk avatar May 25 '20 15:05 anthem-bmk

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Jun 26 '20 05:06 stale[bot]

I’ll see if I can find some time soon to take a look at this. Hopefully it’s not a huge code change and it would be nice to get this fixed.

On Thu, Jun 25, 2020 at 22:30 stale[bot] [email protected] wrote:

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/facebook/create-react-app/issues/8813#issuecomment-649977871, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAUP7BUXP4VFLN6OPV2GSTRYQW6VANCNFSM4MEXBMDA .

redbmk avatar Jun 26 '20 05:06 redbmk

Just ran into this too.

jeffersoneagley avatar Jul 24 '20 18:07 jeffersoneagley

Ran into this as well - trying to host multiple react sites under a single domain \(〇_o)/

tsharp avatar Jul 24 '20 18:07 tsharp

Having the same issue here.. any update?

fonziemedia avatar Aug 20 '20 15:08 fonziemedia

Does anyone have a fix for this other than changing version to [email protected]? I changed the version and it created an issue as follows: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

Found the fix. Changed react-dev-utils to 10.1.0

Appreciate you sharing this but it did not work for me..

fonziemedia avatar Aug 20 '20 15:08 fonziemedia

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Sep 20 '20 03:09 stale[bot]

Bump - this is still an issue. I'll try to find time to look into this soon.

redbmk avatar Sep 20 '20 06:09 redbmk

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Dec 25 '20 20:12 stale[bot]

I have an open PR for this: #9771

is anyone able to review it? @elvisLAI ?

redbmk avatar Dec 26 '20 17:12 redbmk

hi. Has there been any progress on this? I would also like a solution :)

i-am-b-soto avatar Feb 18 '21 00:02 i-am-b-soto

I fixed a similar error by setting the homepage on package.json to an empty string:

   "homepage": "",

Before I did that I was getting the app initialised locally with unwanted URL, something like:

  Local:            http://localhost:3000/this-and-that/and-some-more
  On Your Network:  http://192.168.1.47:3000/this-and-that/and-some-more

dreamyguy avatar Mar 15 '21 16:03 dreamyguy

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Jun 26 '21 03:06 stale[bot]

I'll try to remember to update my PR since I'm sure there are conflicts by now, but I don't think anyone ever reviewed it. Is there someone that would be willing to give some feedback on #9771?

redbmk avatar Jun 28 '21 16:06 redbmk

This is an insidious bug. I was able to resolve this for myself using the following steps:

  1. Add a .env file in the same folder as package.json
  2. Populate it with PUBLIC_URL=https://example.com. If you're trying to set this up with github pages then you will likely need PUBLIC_URL=https://user-name.github.io/repo-name.
  3. Run npm run build. After these steps I was finally able to see my react site render correctly. In my use case I was trying to host a site using github pages and a custom domain name. This bug ensured that my react app continued to look for my site's contents under the custom domain instead of the github domain listed under homepage in package.json.

sgaweda avatar Aug 30 '21 04:08 sgaweda

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Jan 09 '22 14:01 stale[bot]

Having the same issue!

pal85adam avatar Jan 19 '22 19:01 pal85adam

Still happening as of today. The homepage property in package.json appears to be completely ignored by yarn build.

nathan-alden-sr avatar Aug 01 '22 03:08 nathan-alden-sr