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
Error with assets loading from scss in Angular #24272
Comments
What is working for me is to use relative paths for the images in the SCSS files. So
And
See if those changes work for you as well. |
I'm pretty sure it would work for me too, but when you have nested components that load assets from scss it's pretty bad to have relative links instead of absolute. Having a link looking like this And if the asset gets moved or the component is moved up or down in the folder hierarchy you have to check all the links. Thanks for your suggestion, I might be able to use it as a temporary fix until I can use absolute pathing again. Even though I don't like the idea of changing my code so that the testing library works, it feels weird. |
Hey team! Please add your planning poker estimate with Zenhub @amehta265 @astone123 @lmiller1990 @marktnoonan @mike-plummer @warrensplayer @ZachJW34 |
Debugging this one... looks like we have some special logic for imports in JS here: https://github.com/cypress-io/cypress/blob/develop/npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts#L84 but it's likely not applied for scss imports. Also a high level google search yields something similar relating to webpack and scss. I'll keep investigating. |
Does Angular provide any concrete recommendations for using |
You might want to checkout out the |
Interesting - I found another work around, which is just to re-proxy any non absolute requests (eg on the same domain) here to the dev-server endpoint, but it's a bit of a hack. I will try playing with |
I tried various settings for Edit: yes, |
I am going to try something a bit more heavy handed and see if it breaks anything. This might solve some other outstanding issues around incorrect asset requests, too. There's probably a more correct, Angular specific way to solve this (which might require some unexposed internal API?), but doing these case-by-case fixes is starting to get a bit hard to maintain. Maybe this "just proxy it" option might be better in the long run. Draft PR: #25120 Ah, this breaks |
Update... trying something out: cb2f23b My idea is forward all traffic to The edge case is if users want to intercept traffic to localhost via This might break things - if everything is green, we can probably consider moving ahead with this. If not, I think we will need to explore more framework (eg Angular specific) fixes to solve this issue. |
I think the problem is related to resolving images in SCSS via They've also got a
It always errors:
I guess this doesn't work with a virtual filesystem? 🤔 |
Ahh I did it! Several hacks, let me write it down before I forget.
Here's a screenshot showing the file. Line 245 is the trick. Obviously hacking into What we could do is set |
I did it, I have fixed the bug. I will make a PR. This was very time consuming and painful, and I am glad it's finally fixed. |
For now #25191 will be a quick and low risk fix, letting Angular users support |
Current behavior
Loading assets from scss with something like this :
Image is showing using
ng serve
but not when using cypress component testingIf I remove the '/' in the url, image load in component testing but angular won't compile with the following error :
Another loading problem comes from loading assets in scss "main" files, I have a
main.scss
containing :For simplicity purposes I didn't use abstracts variables and mixins.
components/icons
:app.component.html
:If I remove the
/
here, images won't load from assets since it's using relative path and it will try to loadassets/components/test.png
andng serve
won't compile with the same error above.Desired behavior
I would like to be able to load all my assets, I've given a sample app reproducing the issue below, but in my real-world app, I can't load any of my svg that comes from scss and all the fonts I use aren't loaded since I'm using
@font-face
with urls in scss and they can't be resolved.Test code to reproduce
Repo with code: https://github.com/theoarmengou/angular-cypress-bug-assets
When doing
ng serve
, you should see 4 images onlocalhost:4200
and when going tolocalhost:4200/dev
, there should be 8 images.When using
yarn cypress:open
in component testing, not all images are showing forapp.component
anddev.component
.Cypress Version
10.10.0
Node version
16.16.0
Operating System
macOS 12.5.1
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: