question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative PUBLIC_URL during development

See original GitHub issue

Describe the bug

I am unable to get relative urls to assets during development, only when building release.

Am I doing something wrong?

{
...
  "homepage": ".",
...
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
...
  },
...
}
# building release works as expected
$ yarn build 
✨Done in 4.55s. 
$ grep -o '\"[^\"]*favicon[^\"]*\"' build/index.html
"./favicon.ico"

# homepage value is ignored during development, get absolute assets urls
$ yarn start
$ curl --silent http://localhost:3000 | grep -o '\"[^\"]*favicon[^\"]*\"'
"/favicon.ico"
"/favicon.ico"
"favicon.ico"
"/favicon.ico"

# PUBLIC_URL set to . for relative urls, get absolute urls
$ PUBLIC_URL=. yarn start
$ curl --silent http://localhost:3000 | grep -o '\"[^\"]*favicon[^\"]*\"'
"/favicon.ico"
"/favicon.ico"
"favicon.ico"

# PUBLIC_URL set to /some/path, this works but with absolut path as specified
$ PUBLIC_URL="/some/path" yarn start
$ curl --silent http://localhost:3000 | grep -o '\"[^\"]*favicon[^\"]*\"'
"/some/path/favicon.ico"
"/favicon.ico"
"favicon.ico"
"/some/path/favicon.ico"
"/favicon.ico"

# PUBLIC_URL set to ./some/path, get absolute urls but without specified path
$ PUBLIC_URL="./some/path" yarn start
$ curl --silent http://localhost:3000 | grep -o '\"[^\"]*favicon[^\"]*\"'
"/favicon.ico"
"/favicon.ico"
"favicon.ico"
"/favicon.ico"

Did you try recovering your dependencies?

(Write your answer here.)

Which terms did you search for in User Guide?

(Write your answer here if relevant.)

Environment

Environment Info:

  current version of create-react-app: 3.4.1
  running from /Users/USER/.npm/_npx/49546/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.6
  Binaries:
    Node: 14.7.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.7 - /usr/local/bin/npm
  Browsers:
    Chrome: 84.0.4147.135
    Firefox: 79.0
    Safari: 13.1.2
  npmPackages:
    react: ^16.13.1 => 16.13.1
    react-dom: ^16.13.1 => 16.13.1
    react-scripts: 3.4.3 => 3.4.3
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. Create new app with create-react-app
  2. Set homepage value to . for relative asset urls for built releases
  3. Test different values for PUBLIC_URL will give you absolute urls

Expected behavior

Expect relative urls for assets when PUBLIC_URL is set to ..

Actual behavior

All PUBLIC_URL values are ignored that starts with ., will always produce index.html with absolute asset urls.

Reproducible demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
StefanoGermanicommented, Oct 7, 2020

I have got the same problem, any news?

0reactions
iansucommented, Jun 2, 2021

Can you try the latest release and see if this has improved? If not please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run with Relative Paths in development #3188
It is possible to build for Relative Paths. How would I do the same when running in development using npm start?
Read more >
Configure the create-react-app public URL post-build with ...
Have you considered using relative URLs? PUBLIC_URL=. Results in URLs like "./favicon.ico". Then you can deploy your app to any folder, like / ......
Read more >
Can't build create-react-app project with custom ...
Note that it is a relative url, this completely simplifies the ability to run locally and hosted. The basename value, matches the repository ......
Read more >
Public Path
It allows you to specify the base path for all the assets within your application. Use Cases. There are a few use cases...
Read more >
Gatsby Blog From Scratch: An In-depth Guide to Starting with ...
First, create a publicURL field in node data which will tell us where each file we process will sit in the public directory....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found