Skip to content

Media URLs are incorrect in CSS #13394

@boonware

Description

@boonware

Describe the bug

I am serving my app under a path such as https://my-site.com/somePath. When running a build I set the variable PUBLIC_URL=somePath, and I have also set <base url="%PUBLIC_URL%" /> in index.html . This correctly updates the output files with the correct paths, except for URLs in the CSS, for example:

https://my-site.com/somePath/static/css/somePath/static/media/some-font.woff2

As you can see the CSS URL is incorrect and is not referencing the media directory relative to the CSS file.

Did you try recovering your dependencies?

Yes, and likely not applicable.

Which terms did you search for in User Guide?

Webpack, media, static, build

Environment

Environment Info:

current version of create-react-app: 5.0.1
running from REDACTED/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

System:
OS: macOS 13.5.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 18.12.0 - ~/.nvm/versions/node/v18.12.0/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v18.12.0/bin/npm
Browsers:
Chrome: 117.0.5938.149
Edge: Not Found
Safari: 16.6
npmPackages:
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
react-scripts: 5.0.1 => 5.0.1
npmGlobalPackages:
create-react-app: Not Found

Steps to reproduce

(Write your steps here:)

Expected behavior

Media file URLs in CSS should be relative to the CSS file and not incorrect as shown above.

(Write what you thought would happen.)

Actual behavior

Media paths are incorrect.

(Write what happened. Please add screenshots!)

Reproducible demo

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions