question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scss styles background image parse error

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
cyrilwannercommented, May 4, 2020

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 the imgName variable can have.

I think there are two solutions:

  • If all the images in imgName have the same extension, you could move the extension out of the variable: require(`../public/images/${imgName}.jpg?...`)
  • You can create multiple directories and move the images into subdirectories. E.g. move all svg files into a icons directory, background images into backgrounds, 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

2reactions
cyrilwannercommented, Apr 2, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found