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.

Plugin doesn't work with webpack 5 / Next.js 11

See original GitHub issue

Thanks 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:open
  • Created 2 years ago
  • Reactions:25
  • Comments:7

github_iconTop GitHub Comments

31reactions
mystrdatcommented, Aug 12, 2021

If next11 does static image optimization itself, what is the benefit of using this package now?

As of now, the next/image component is garbage.

29reactions
jaimemassoncommented, Jun 24, 2021

the actual fix for this is to disableStaticImages in nextjs config. see https://nextjs.org/docs/basic-features/image-optimization#disable-static-imports

Read more comments on GitHub >

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

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