cyrilwanner / next-optimized-images

🌅 next-optimized-images automatically optimizes images used in next.js projects (jpeg, png, svg, webp and gif).
MIT License
2.21k stars 93 forks source link

Can't use .svg?include since 2.5.6 #142

Closed esiao closed 4 years ago

esiao commented 4 years ago

Hello,

I've came across an issue recently upgrading my depencies. It looks like since version 2.5.6 the raw-loader isn't loaded properly and during the build I have errors of the likes of, resulting in error 500.

./assets/something.svg?include 1:0
Module parse failed: Unexpected token (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
> <?xml version="1.0" encoding="utf-8"?>

If I downgrade to 2.5.5 the issue is gone and I can use my svgs as expected. const Something = require('../assets/something.svg?include')

Hope this will help people coming across this issue until it's fixed.

Thanks for your hard work.

cyrilwanner commented 4 years ago

Hello @esiao Can you provide me more information about the versions you are using? Did you also try 2.5.7 (which fixed a similar problem)? And which nextjs version are you using? Are using the @zeit/next-css|sass plugins or did you migrate to the builtin nextjs css solution (introduced in 9.2/9.3)? Thank you already!

kolyasapphire commented 4 years ago

Hi! Having a similar issue, but for: require('xxx.jpg?resize')

Getting:

Error: 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)

Next.js: 9.3.4 next-optimized-images 2.5.7

responsive-loader: 1.2.0 sharp: 0.25.2 webp-loader: 0.6.0 imagemin-mozjpeg: 8.0.0 imagemin-optipng: 7.1.0 imagemin-svgo: 7.1.0

kolyasapphire commented 4 years ago

Tested - this errors are not happening in next-optimized-images 2.5.5, even with latest Next 9.3.4. I am using built-in Next CSS.

esiao commented 4 years ago

Hello @esiao Can you provide me more information about the versions you are using? Did you also try 2.5.7 (which fixed a similar problem)? And which nextjs version are you using? Are using the @zeit/next-css|sass plugins or did you migrate to the builtin nextjs css solution (introduced in 9.2/9.3)? Thank you already!

Here are my modules versions

I tried with 2.5.7 and 2.5.6, I had to roll back to 2.5.5 where I don't have the issue. (today still) I'm using the built in sass modules but the icon is in a react component. It's using a dynamic require in the likes of const Icon = require(`[...]/${icon}?include\`) to fetch the icon. Hope this helps.

cyrilwanner commented 4 years ago

That did indeed help, thank you!

I just published a canary version: 2.5.8-canary.1 Can you maybe try this version in your project and tell me if everything works again as expected? If that is the case and I am sure it doesn't break anything else, I will release it with the latest tag.

kolyasapphire commented 4 years ago

Fixed the issue for me, thank you very much!

esiao commented 4 years ago

That did indeed help, thank you!

I just published a canary version: 2.5.8-canary.1 Can you maybe try this version in your project and tell me if everything works again as expected? If that is the case and I am sure it doesn't break anything else, I will release it with the latest tag.

Hi I'm sorry I didn't answer earlier I had an hectic week! It's working perfectly fine now, thank you. I'm looking forward the next release with the fix, glad I could help you debug the issue. Thank you very much.

cyrilwanner commented 4 years ago

No worries, we all have those weeks.

I'm glad to hear that everything works, thank you again! The fix is now published as a non-canary version in 2.5.8.