scss styles background image parse error
See original GitHub issueHi, thanks for your work at first
Describe the bug
After upgrading to 2.5.6, next build errors with:
Failed to compile.
./app/components/FileLoader/styles.scss
ModuleParseError: Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
> Build error occurred
Error: > Build failed because of webpack errors
System information
- System macOS Catalina 10.15.3
- node 12.8.0
- npm 6.10.3
- next 9.3.3
- next-optimized-images 2.5.6
Additional context
with next-optimized-images 2.5.5 everything ok, an error occurs in styles files with background images
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Why do I get a parse error when trying to add a background ...
Just use quotes and then whitespace is okay. Single or double: background-image: url('../Project Img/camping sky.jpg');.
Read more >Css3 background image fails - HTML & CSS - SitePoint Forums
You really want to reference your images folder from the CSS file, as that will work locally and online. E.g. /css/ styles.css /images/...
Read more >How to fix CSS background-image not working | HTML/CSS
1. Check that your CSS file is linked correctly in your HTML file. In order for your CSS styles to get loaded in...
Read more >CSS background-image error - HTML / CSS - Bytes
I want to use an image I have as a background, but every time, Firefox 2.0.0.7 returns an error that says: "Error in...
Read more >CSS Background Image Not Working - Position Is Everything
If the CSS file is not properly linked to the HTML file, the background would be white and not show any style or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @xeniajensen This is a slightly different issue and has to do with the dynamic require.
When using a dynamic require, webpack applies the loaders on all files that could match this require. Because at build time, it does not know which images will be used later. So when you use
../public/images/${imgName}
, it applies the loaders to all images within that folder, regardless of their extension since webpack does not know which extensions theimgName
variable can have.I think there are two solutions:
imgName
have the same extension, you could move the extension out of the variable:require(`../public/images/${imgName}.jpg?...`)
icons
directory, background images intobackgrounds
,thumbnails
, etc… This also has the advantage, that your query will only get applied on the images you need it to be applied and not just on all you have (regardless if they are really used in this size or not).You can read more about it here: https://webpack.js.org/guides/dependency-management/#require-with-expression
I’m very sorry that this version broke your builds. I just published
v2.5.7
which should hopefully fix them again. Can you please verify that?Also, if you are already on nextjs 9.3, you might want to consider switching to the builtin sass solution which got introduced in 9.3 so you wouldn’t need the
@zeit/next-sass
plugin anymore.