Plugin doesn't work with webpack 5 / Next.js 11
See original GitHub issueThanks a lot for this excellent plugin, it’s been really helpful for us!
Problem
This plugin doesn’t work correctly when using Next.js 11. Attempts to require
images result in an error like the one below during the build:
Failed to compile.
./src/images/my-awesome-image.svg
TypeError: unsupported file type: undefined (file: undefined)
Workaround
It seems like the problem is due to the fact that from version 11 Next.js uses Webpack 5 by default. It looks like it’s possible to work around this issue by forcing the use of Webpack 4. This is done by setting webpack5
to false
in next.config.js - see the webpack5 option docs for more.
Edit: rather than disabling webpack5, this can be solved more neatly by toggling disableStaticImages
in the nextjs config. See @jaimemasson’s comment below.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:25
- Comments:7
Top Results From Across the Web
Webpack 5 Adoption - Next.js
Custom webpack configuration When using webpack plugins make sure they're upgraded to the latest version, in most cases the latest version will include...
Read more >How to use webpack 5 configs in Next.js? - Stack Overflow
and when I yarn dev I get the following error: - configuration[0] has an unknown property 'experiments'. If you notice the required module...
Read more >To v5 from v4 - webpack
This guide aims to help you migrating to webpack 5 when using webpack directly. If you are using a higher level tool to...
Read more >Build Micro frontends in NextJS and ReactJS with Webpack 5 ...
Similar to code-splitting, we use dynamic import to load remote modules(aka micro frontend applications) in the application container. We could ...
Read more >next js module not found: can't resolve 'fs' - You.com
Since version 5, webpack doesn't include polyfiles for node libraries. In your case, you most likely need to add resolve.fallback.fs: false to your...
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
As of now, the
next/image
component is garbage.the actual fix for this is to disableStaticImages in nextjs config. see https://nextjs.org/docs/basic-features/image-optimization#disable-static-imports