-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Assets not found in scss/css when using base-href #4782
Comments
I'm having the same issue. Building with href flag makes my assets folder unreachable to my code. If i navigate to the path in the browser with the href put into it, the image gets loaded. I should add that i dont use it in the scss but simply adding a Is there a workaround to this? Kind regards - Chris |
@chriseenberg this actually works fine for me: simply use
and make sure your assets folder is set in .angular-cli.json in the assets section. |
It seems that what ever you linked is broken :/ where it says: "simple use " and then something that i can't resolve. Thanks for answering my post. I tried adding the assets folder to angular-cli.json, but it will prefix my assets folder with the specified href tag so i cant reach my images i.e. href = xxx - xxx/assets/images - where i look for assets/images . From what i understand from your post, this is supposed to work? Im sorry if i misunderstood your post in the first place :) |
The root relative URL handling for style sheet urls is currently broken if using a base href. As a workaround you can use a relative URL that is referenced from the stylesheet instead of the project root. This will cause the asset to be managed by the build system so be aware that you will end up with two copies if the asset is also copied on build. Also note that, HTML templates are unaltered by the build process. |
It works now. i navigated to the resource with ../ instead of ./ as you said @maxpfandl ! Thank you so much for your help! |
I'm having the same problem. Relative paths in stylesheets don't work after updating to angular-cli beta 32.3. |
If it is helpful to you, I can try to make a minimal repro of this issue. |
Please try using a relative path from the stylesheet/component location instead of the project root. |
@clydin I tried doing that, but that didn't help. Actually, having to use a relative path is a part of the problem. The problem in my case, is that I used to link the image like this, in the scss: This would work, as the url path wouldn't be touched/changed, and the image placed in But in the latest version of angular-cli, that won't compile. If I change to a path relative to the scss file, as @clydin suggests, then angular-cli will happily compile it. But now the problem is that the url in the output CSS will look like this: This works okay on the development server, but it does not work on the production server, because the image is not copied to the web root in the |
Correction: The image is copied to the root when doing But the image is not copied to the root when doing |
I am having the same/similar issue -- with no baseHref set. In a component scss file I have the following:
When I do an
|
relates to #4778 |
Fixing component css in angular#4667 uncovered errors in CSS url processing. This PR correctly composes absolute urls when using `--base-href` and/or `--deploy-url`. Fix angular#4778 Fix angular#4782
Dupe of #4778. Please check out @clydin's great answer at #4778 (comment) regarding exactly what happened. |
Fixing component css in angular#4667 uncovered errors in CSS url processing. This PR correctly composes absolute urls when using `--base-href` and/or `--deploy-url`. Fix angular#4778 Fix angular#4782
Fixing component css in angular#4667 uncovered errors in CSS url processing. This PR correctly composes absolute urls when using `--base-href` and/or `--deploy-url`. Fix angular#4778 Fix angular#4782
Fixing component css in angular#4667 uncovered errors in CSS url processing. This PR correctly composes absolute urls when using `--base-href` and/or `--deploy-url`. Fix angular#4778 Fix angular#4782
Fixing component css in angular#4667 uncovered errors in CSS url processing. This PR correctly composes absolute urls when using `--base-href` and/or `--deploy-url`. It also fixes asset output on `--aot` mode. Fix angular#4778 Fix angular#4782 Fix angular#4806
Fixing component css in angular#4667 uncovered errors in CSS url processing. This PR correctly composes absolute urls when using `--base-href` and/or `--deploy-url`. It also fixes asset output on `--aot` mode. Fix angular#4778 Fix angular#4782 Fix angular#4806
I used background: url(...); in the scss file to insert a background image instead of background-image: url(...); and it worked |
@martinmcwhorter did you find any solution? I am having the same problem in a scss file |
fhbgjtgyjhuyhj |
@maxpfandl it works for me... just modifying "../" to "./" at the resources ... so much thanks to you man :) |
Seems like the latest angular cli (v6) is not passing the base-href to the postcss, making postcss mess up the paths. I can't prefix my urls with / or with ../ since both will mess up the path. The path needs to be relative since i have a base-href for my solution. The angular CLI already reads the base-href and uses it for parsing assets, everywhere except passing it to postcss. Any paths inside .scss files will eventually work once the solution hits production, but in non prod builds, postcss will output errors/warnings since it does not know about the base-href |
I see that this issue is closed but nobody provided a solution or a work around, so how do I solve it??? I have a This code working great in This happens because in production the browser is looking for the fonts at: So how do I solve this problem?? Does anyone has a work around???? P.S I try to change the url: I'm running Angular 6.x P.P.S |
This happens because the server that controls the requests redirects to your app only the requests that begins with
I know that It's not a ideal solution but it resolves until find a better alternative |
Looks like some of the webpack-isms work for this issue too, ie |
@the-destro What about the JS and CSS resources, once |
Same problem than @Gil-Epshtain |
In my case |
In my case it was : But i have remaining issue with fontawesome dependencie...
So i have square instead of icon. Link in the console worked. Any fix ? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
Windows 10 x64
Versions.
@angular/cli: 1.0.0-beta.32.3 [1.0.0-beta.28.3]
node: 7.2.0
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.32.3
@angular/compiler-cli: 2.4.7
Repro steps.
create an app with ng-cli. create a build for a server (not ng serve) with base-href set to xxx. use url's in scss (like background-image: url('/assets/img/myimg'). the imagepath for the url will be set to server/assets/img/myimg instead of server/xxx/assets/img/myimg. If I try to use a relative path in the scss (ie url('./assets/img/myimg') ) i get a compileerror, that this is not resolveable. If i try to use url('assets/img/myimg') this is also not resolveable for the compiler.
my .angular-cli.json has this section:
"assets": [
"assets",
"favicon.ico"
],
The log given by the failure.
There is only a compileerror that the path is not resolveable or a runtime 404 when the resource is not found without using the base-ref in the url.
Mention any other details that might be useful.
There is a workaround for this issue: i set the style in my component directly and inject it like this:
<span ... [style.background-image]="getLogo()">
getLogo() {
return this._domSanitizer.bypassSecurityTrustStyle(
url(${this.logosrc}
);}
where logosrc = "./assets/img/myimg"
The text was updated successfully, but these errors were encountered: