-
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
Module not found: Error: Can't resolve file #4778
Comments
Same thing here. Technically, at development time, the path is wrong because the file has not yet been compiled into the location it will be at runtime. So I'm assuming I need to specify the location in the configuration somewhere? |
For reference my
(Which was working fine in beta.31 as mentioned earlier) |
I've got the same; still getting the error |
me too
|
CSS URL handling was changed. To replicate the behavior prior to beta.32, use a root relative URL (i.e., add a / to the beginning of each URL). |
I tried that and it did compile with no errors, but then at runtime it was looking for 'assets' in the root of the url rather than in the root of the web context. So none of my images loaded..... |
Thanks @clydin - it started working again for me by adding '/' before all relative URLs in the SCSS files. @billdwhite do you have the 'assets' in your .angular-cli.json file as mentioned above? |
Yes I do have that in my files. But I'm running the app from a subcontext (think http://myserver/myapp as opposed to http://myserver) so the path that results from using / before the relative urls results in it looking for http://myserver/assets/myimage.png which is wrong. (It needs to be http://myserver/my app/assets/myimage.png) so I'm guessing I'm missing some other config setting that tells it to adjust for that. Maybe base href or something but that seems to be set correctly for everything else in my app so I'm not sure what I'm missing. Again, setting the / does fix the compile errors but it just doesn't work at runtime. |
I have the exact same behaviour as @billdwhite. Adding a slash maybe fixes the compilation error but it's no final solution and wasn't necessary in the past. |
@filipesilva is it possible this was caused by your commit from 3 days back? |
Yes it is likely related. I'll have a look. |
If you don't want them processed, a root relative URL will prevent this behavior. Unfortunately, this will currently conflict with custom base hrefs and deployUrls. This is in the process of being corrected. Also of note is that global stylesheets already function in this manner. |
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
First of all, apologies for the breakage. @clydin's answer above explains what happened well. Further clarification: 'root relative URLs' are those that start with As to why this change... it was because component css did not support imports, and in fixing that we inadvertently also fixed Before it didn't actually work insofar as images/etc where never processed. Now they are (as long as it's a relative url). This also means that you can just put your images locally, side by side with your css. They will be correctly recognized and placed in the output directory, and even get hashes on prod builds. You don't need to put them in If you do want to put them in For instance, from I just pushed a PR that should fix base-href and deploy-url broken interaction: #4803. |
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
@filipesilva Thanks for your clarification. However, I'm still having problem with images not being copied in production builds, see #4806. I don't know if this was fixed in your fix? |
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
If url() is now processed, I believe In my less file I'm having to use two ways to reference a file.
|
Hi, one solution for me is, put some styles like this in: styles.css |
I am facing a similar problem with @angular/cli version 1.0.0. background-image: url('/./assets/images/account.png') Note that I am using "ng build --env prod --base-href ." to build the project. Does anyone know which version has the fix for this? |
Solved that by disabling of |
@billdwhite hey did you ever end up solving your issue? I'm facing the same scenario. |
@aliyeysides that was so many months back that I'm not sure how I solved it. Regardless, I have been using ~ in my asset paths to like this: @import '~assets/styles/variables.scss'; so maybe that will work for you to specify an assets folder in the root of the project that is running from a non-server root endpoint. |
[](ERROR in multi script-loader!./ ERROR in multi script-loader!./ ERROR in multi script-loader!./ ERROR in multi ./ ERROR in multi ./ ERROR in multi ./src/polyfills.ts ERROR in multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts ERROR in Error: Child compilation failed:
ERROR in multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts |
Please help me ... npm run dev ERROR Failed to compile with 1 errors 00:33:59 This dependency was not found: /var/www/html/screp/resources/assets/sass/app.scss in multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss ERROR in ./resources/assets/js/app.js
|
@filipesilva @romulo1984
How would you add a root reference in @import? For example: Because in my current implementation this currently creates an error in saying it cannot resolve the path location.
I have defined the "common" path mapping in tsconfig.json:
and yes, "variables.scss" does exist in the "app/common/styles" folder. |
background-image: url('/assets/images/icon-search.png'); works on mine, add / to assests... so /assets... and also don't do background-image: url(""); empty source with double"" or single'' quotes, it gave me error saying ERROR in ./src/styles.css Module build failed: ModuleNotFoundError: Module not found: Error: Can't resolve './.' in ...... |
Is this broken again in 1.7.0? |
@dcatoday having the same problem as you in 1.7.0, I think it's broken again |
I still don't see a clean way, how to reference urls in sass with a relative path that works both in dev and prod (app not running in root directory). If I reference my image and font urls with 'root relative urls' like url('/assets/some-font.ttf') everything works fine in dev but I can not run my app in a subfolder on the server. If I use relative urls starting from my sass file like url('../fonts/some-font.ttf'), my dev environment works fine as well but all assets referenced in sass get packaged into the root of my app instead of the assets folder. For reasons of our deployment process and prod environment I am not using base href, but HashLocationStrategy. |
Guys, Google Mobile Friendly Test failed (https://search.google.com/test/mobile-friendly), because it was not able to find the background-image. This is how I started to search for a solution. Actually starting with '/' didn't help me at all... but starting with './' was the solution. (Angular 6) |
I'm running Angular CLI version
this happens only in production and only when the app runs in a subdomain. |
Just want to add another vote.. because paths in my scss is also not working for me. If I do not absolute it works when running with EDIT: background: cover #da4877;
background-image: url("/assets/bar.png");
background-size: cover; after I changed the first line to So please Ignore my vote on this ;) |
Hey, did you find any solution for this issue? I'm facing the same issue. |
@isahilpahuja , the workaround (not a proper solution) I've found is to move your image reference from the styles to the template. It feels icky but it "works." So instead of: // article.scss
.article__photo {
background-image: url(assets/bacteria.svg);
} do this instead: <!-- article.html -->
<div class="article__photo" style="background-image: url(assets/bacteria.svg);"></div> Though this workaround may not be reasonable if you're wanting to apply the background image to many elements. Another possible workaround is to eject the webpack config and fiddle with the CSS file-loading, though I'm no webpack expert but I assume it could likely be done... Of course, at the expense of the ejected webpack config which I personally find intimidating... |
@Empereol Thanks a lot! I moved it from styles to template and it worked. But still didn't able to find the reason why it was not working when placed in scss file. |
…ll three location: 1.local demo, 2.storybook, 3.publish package worked as well. (should have test this in the convert-css-scss branch). It's a ugly solution, people already raise it. (angular/angular-cli#4778). See if you can improve in the future.
Any update on this? This problem has been there very long now and it's still not being addressed. I was not able to find clean way to reference assets in scss files that would work both for dev and production. Absolute path works in dev environment but not in prod when application is hosted in subdomain, relative path on the other hand forces me to reference different path depending on location of scss file. |
This was working for me just fine in Angular7 with the Any news? |
Until now I have faced the same problem.
I'm now using just "assets/..." and it works for me on development and production. EDIT: I don't know why, but my images are copied next to the assets folder but there are copies in my assets folder, too. Does anyone knows the reason? |
@julianpoemp this is well explained above #4778 (comment), |
ProblemI am having a similar problem; I have manually replaced the More details:We build artifacts without knowing where they will be deployed. Deploying artifacts involves setting the I have read the responses by @clydin #4778 (comment), and @filipesilva #4778 (comment), but find them confusing because:
I have read (webpack-contrib/extract-text-webpack-plugin#246 (comment)) that disabling the url processing by the Does the Angular CLI have a solution to this problem, or is a custom Webpack Config the "correct" solution? If yes, then what version of the Angular CLI supports the solution (since we are using v6)? |
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. |
After the update to beta.32.3 i started getting these errors in SCSS files:
The error seems to appear in this line:
P.S: It was working fine on beta.31
The text was updated successfully, but these errors were encountered: