SCSS modules cannot load images correctly with `next-images` package
See original GitHub issueUpdate: Read my other comments below for a more pinpointed problem.
Bug report
Describe the bug
I tried to set a background image in a SCSS module with background: url("./footer-region-bg.jpg") repeat; (is in the same directory as the component). But this results in the following when fetching the image.

This was working with @zeit/next-sass, but it doesn’t with the native scss modules.
To Reproduce
Load an Image from the same directory as the component in an SCSS module like mentioned above. Use the native SCSS modules from NextJs.
Expected behavior
The image should be loaded correctly
System information
- OS: Windows
- Version of Next.js: 9.3.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:17 (5 by maintainers)
Top Results From Across the Web
Unable to import images in nextjs using next images package
There is no need to load the image via the import if you add the images to /static/. You can use like this...
Read more >next-images - npm
next-images package contains definitions for image modules, you need to add reference to next-images types into a type definition file, e.g. ...
Read more >next/image - Next.js
The default loader does not optimize SVG images for a few reasons. First, SVG is a vector format meaning it can be resized...
Read more >All you need to know about images in Next.js - DatoCMS
In other words, treating Next.js images correctly is now vital. ... But thanks to the <Image> component, you do not have to worry...
Read more >Next.js image optimization techniques | Uploadcare Blog
Not so long ago, Next.js developers added an Image component to the framework which was aimed to replace the native HTML image and...
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 Free
Top 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

I’m not sure if it is a
next-imagesissue or the Next.js itself.I faced the same issue after upgrading from
9.1.7to9.3.1. I was usingnext-sassandurl-loaderwith the custom webpack config.By using the built-in Sass feature, background and font face
url()s inside.scssfiles stop working. After digging into Next.js files I realized that it handlesurl()imports through thefile-loadernow.https://github.com/zeit/next.js/blob/v9.3.1/packages/next/build/webpack/config/blocks/css/index.ts#L278-L292
https://github.com/zeit/next.js/blob/v9.3.1/packages/next/build/webpack/config/blocks/css/index.ts#L17
I hadn’t used the built-in CSS feature before and that is why I hadn’t faced the issue.
Workaround
I ended up with excluding the
url()file imports by setting a test regex in webpackissuerconfig as follows:Hope this helps.
Solved!
style.module.scss
next.config.js