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.

Image component fails when using image data URI

See original GitHub issue

Bug report

Describe the bug

When passing an image data URI to the Next.js image component an error is thrown.

To Reproduce

Pass data URI to the Next.js image component:

Example:

import Image from 'next/image';
<Image src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=">

Expected behavior

The simplest solution and expectation would be to pass the URI directly to the img tag without any modification or optimization.

Screenshots

Not applicable but error reported on the debug overlay is:

Error: Invalid src prop (data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=) on `next/image`, hostname is not configured under images in your `next.config.js`

System information

  • OS: Windows
  • Browser (if applies) Chrome, Firefox, Edge
  • Version of Next.js: 10.0.0
  • Version of Node.js: 12.9.0

Additional context

None.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:21
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
AlexSapoznikovcommented, Oct 28, 2020
  1. Also can not load static image: https://github.com/vercel/next.js/discussions/18311
  2. Image with empty src should probably not throw an error as well… <Image src="" ...
1reaction
brnyzacommented, Aug 19, 2021

Unfortunately enabling unoptimized doesn’t do the trick atm (using next@11.0.1-canary.4).

For me it worked writing like this on Next.js v11.0.1: <Image unoptimized src={data:image/jpeg;base64,${imageBase64}} alt="Landscape picture" width={300} height={300} />

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load image from data Uri - android - Stack Overflow
I am receiving a data uri from a remote API using retrofit. I tried many methods yet not able to get the image...
Read more >
Is data URI in <img> tag not supported? - Meta Stack Exchange
Tried it out in the sandbox, and it looks like data URI doesn't work with PNG either. This is what I tried so...
Read more >
data URI scheme - Wikipedia
The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to ... This technique allows normally separate elements...
Read more >
HTMLCanvasElement.toDataURL() - Web APIs | MDN
toDataURL() method returns a data URL containing a representation of the image in the format specified by the type parameter.
Read more >
datauri - npm
The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to include data in-line in web pages as...
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