Skip to content

absolute imageurls in stylesheets incompatible with @angular/localize #29972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
StefanKern opened this issue Mar 31, 2025 · 4 comments
Closed
1 task
Labels
needs: repro steps We cannot reproduce the issue with the information given

Comments

@StefanKern
Copy link

Command

build, other

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

If angular is used with "@angular/localize" and two languages, the build is split into "en" and "de". Now if a image image is linked in a stylesheet with an absolute url (e.g. "background-image: url('/https/github.com/assets/1.jpg');", this works in development, but once the application is deployed, the image is not found because the assets folder is not located in the root directory.

Not using a "/" at the beginning, causes the following error

X [ERROR] Could not resolve "assets/1.jpg" [plugin angular-css-resource]

    src/app/pages/startpage/intro/intro.component.scss:11:24:
      11 │   background-image: url("assets/1.jpg");
         ╵                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "assets/intro/intro-minimal.jpg" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
  Preprocessor stylesheets may not show the exact file location of the error.

Using a "~", or "./", etc causes similar build issues. Using relative paths is it's own can of worms and also does not work out of the box...

Minimal Reproduction

.sample-class {
background-image: url('/https/github.com/assets/1.jpg');
]

Exception or Error

404 Image not found in production builds

Your Environment

Angular CLI: 19.2.5
Node: 22.14.0
Package Manager: npm 10.8.1
OS: win32 x64

Angular: 19.2.3
... common, compiler, compiler-cli, core, forms, *localize*
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1902.5
@angular-devkit/build-angular   19.2.5
@angular-devkit/core            19.2.5
@angular-devkit/schematics      19.2.5
@angular/cdk                    19.2.7
@angular/cli                    19.2.5
@angular/material               19.2.7
@angular/ssr                    19.2.5
@schematics/angular             19.2.5
rxjs                            7.8.2
typescript                      5.7.3
zone.js                         0.15.0

Anything else relevant?

#26286
could resolve it.

@alan-agius4
Copy link
Collaborator

Absolute paths are not handled by the build system. Currently, there is no way to output assets directly to the root directory or maintain a single copy.

However, relative paths are supported, as files are fingerprinted (hashed) and copied for each locale and works out of the box. Can you please elaborate on what is the problem with relative paths?

@alan-agius4 alan-agius4 added the needs: repro steps We cannot reproduce the issue with the information given label Mar 31, 2025
@StefanKern
Copy link
Author

Thank you for the fast replay.

In the past I made really bad experiences with relative paths, when it comes to refactoring, however I must say that the now this seems to be very nicely. As far as I read into it, it was just added with angular 17, so I kinda missed it but again, very nice :)

However that leaves the folder build structure i18n interacting very poorly with those absolute urls. So maybe revisit #26286

@alan-agius4
Copy link
Collaborator

Thanks for the additional info, in that case let's keep tracking this in #26286

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2025
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: repro steps We cannot reproduce the issue with the information given
Projects
None yet
Development

No branches or pull requests

2 participants