create-react-app: PUBLIC_URL is not the same as homepage, but only the pathname
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:)
- set homepage in package.json like ‘https://example.com/a/b/c’
- yarn build
- 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
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 19
- Comments: 21
Commits related to this issue
- homepage key is currently broken in package.json, hard-coding instead see https://github.com/facebook/create-react-app/issues/8813 — committed to mmmaaatttttt/color-clock by mmmaaatttttt 4 years ago
- allow homepage to provide a full URL in production Fixes #8813 — committed to redbmk/create-react-app by redbmk 4 years ago
- Change homepage to period There seems to be bug with CRA right now, as a temporaray solution, the homepage has been chnaged to . details here: https://github.com/facebook/create-react-app/issues/8813 — committed to prince-thind/memory-cards by prince-thind 3 years ago
- [Backend] Fix github pages issue (https://github.com/facebook/create-react-app/issues/8813#issuecomment-908021366) — committed to sh4nnongoh/flight-search by sh4nnongoh 2 years ago
Still happening as of today. The
homepage
property inpackage.json
appears to be completely ignored byyarn build
.hi. Has there been any progress on this? I would also like a solution 😃
This is an insidious bug. I was able to resolve this for myself using the following steps:
.env
file in the same folder aspackage.json
PUBLIC_URL=https://example.com
. If you’re trying to set this up with github pages then you will likely needPUBLIC_URL=https://user-name.github.io/repo-name
.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 underhomepage
inpackage.json
.Does anyone have a fix for this other than changing version to react-scripts@3.3.0? 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
I fixed a similar error by setting the
homepage
onpackage.json
to an empty string:Before I did that I was getting the app initialised locally with unwanted URL, something like: