Setting homepage in package.json doesn't set PUBLIC_URL on build
See original GitHub issueDescription
Following the docs here (Building for Relative Paths), so setting homepage
field in package.json
doesn’t set PUBLIC_URL during the build.
Expected behavior
%PUBLIC_URL%
in build/index.html
should be replaced with URL set in package.json’s homepage
field.
package.json:
{
...
"homepage": "https://example.com",
...
}
build/index.html:
...
<script type="text/javascript" src="https://example.com/static/js/main.ec7f8972.js">
...
Actual behavior
%PUBLIC_URL%
will be replaced with nothing.
package.json:
{
...
"homepage": "https://example.com",
...
}
build/index.html:
...
<script type="text/javascript" src="/static/js/main.ec7f8972.js">
...
Environment
Run these commands in the project folder and fill in their results:
npm ls react-scripts
(if you haven’t ejected): 1.0.7node -v
: 8.1.2npm -v
: 5.0.3
Then, specify:
- Operating system: macOS 10.12.5
- Browser and version: Not relevant
Reproducible Demo
create-react-app my-app
(I used create-react-app 1.3.1)cd my-app
- Add
"homepage": "https://example.com"
to package.json yarn build
build/index.html
doesn’t prepend URL to the paths in the script tag
But setting PUBLIC_URL=https://example.com
in .env
and build will produce the expected behaviour (adds URL to the script tag). Setting homepage
in package.json should do the same.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Using `"homepage"` in package.json, without messing up ...
I added a "homepage" to my package.json because it is a React app that I hosted on Github Pages. The output of npm...
Read more >Configure the create-react-app public URL post-build with ...
For a project, I had the requirement of making the public URL of the application configurable via an environment variable that can be...
Read more >Setting homepage in package.json doesn't set PUBLIC_URL ...
The project was built assuming it is hosted at https://example.com. You can control this with the homepage field in your package.json. The build...
Read more >Can't build create-react-app project with custom PUBLIC_URL
The Best Answer is The project was built assuming it is hosted at the server root. To override this, specify the homepage in...
Read more >Deployment | Create React App
You would need to add a 404.html file with the redirection code to the build folder before deploying your project, and you'll need...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Timer if this is the correct use of public_url what is the correct way of setting full URL for the meta tags that require it such as og:image?
People like me who are looking for something like this in in build:
1. Quick Solution
Build your project like this: (windows)
(linux)
(mac) – not sure –
And you will get
in your built index.html
2. Permanent Solution
Create a file called
.env
at your project root(same place where package.json is located). In this file write this(no quotes around the url):Build your project as usual (
npm run build
) This will also generate index.html with:3. Weird Solution
Add this in your package.json
Then index.html will be generated with:
Which is basically the same as:
in my understanding.