-
I get the following error using an image with an absolute url: Nothing in the doc mentions how to configure that. Any hints ? And congrats on the v10 release ! |
Beta Was this translation helpful? Give feedback.
Replies: 27 comments 71 replies
-
My bad, just found the answer here: https://github.com/vercel/next.js/blob/canary/examples/image-component/next.config.js |
Beta Was this translation helpful? Give feedback.
-
So other question: can we use images from random remote sources ? Using |
Beta Was this translation helpful? Give feedback.
-
@timneutkens Can we have a bit information on this here please? |
Beta Was this translation helpful? Give feedback.
-
If the image is svg and present in public/static, how do you load? It's still excepting hostname to be configured! |
Beta Was this translation helpful? Give feedback.
-
Loading an image from a cloudinary url, despite setting the domain as cloudinary.com in next.config.js, doesn't work and triggers this error... |
Beta Was this translation helpful? Give feedback.
-
Hi, a PR was opened here #18325 to add an error document explaining where this hostname needs to be added to correct the error and will be available in a patch release soon. Wildcard values are not yet supported such as |
Beta Was this translation helpful? Give feedback.
-
I had the same error when wanted to use both cloudinary images and images located in the /public dir. I managed to make it work with the fallowing config: |
Beta Was this translation helpful? Give feedback.
-
We use auth0 with social logins. It is a little unfeasible to add each and every potential place a user's profile pic could be stored. For example just google alone requires this: domains: [
'storage.googleapis.com',
'lh1.googleusercontent.com',
'lh2.googleusercontent.com',
'lh3.googleusercontent.com',
'lh4.googleusercontent.com',
'lh5.googleusercontent.com',
'lh6.googleusercontent.com',
], etc. See here for a list of 10k+ sub domains https://securitytrails.com/list/apex_domain/googleusercontent.com |
Beta Was this translation helpful? Give feedback.
-
Anyone have solution for AWS s3 bucket? |
Beta Was this translation helpful? Give feedback.
-
anyone have solution for firebase storage?
|
Beta Was this translation helpful? Give feedback.
-
when i map array and give image link to components, it caches images and shows them incorrectly :| |
Beta Was this translation helpful? Give feedback.
-
I've tried everthing most things suggested here but it's not working. Sigh! how is a library that's suppose to make life eary being this troublesome while configuring? This is my next.config.js ` const withBundleAnalyzer = require('@next/bundle-analyzer')({ const nextConfig = { module.exports = withPlugins([[withImages]], And this is the error I keep getting |
Beta Was this translation helpful? Give feedback.
-
I've been using prismic.io to manage a blog, and I was also getting that error when trying to set up next-config.jsmodule.exports = {
images: {
domains: ['images.prismic.io', 'prismic-io.s3.amazonaws.com'],
// next/image support `srcSet` using the below deviceSizes
// for more info, visit https://nextjs.org/docs/basic-features/image-optimization#device-sizes
deviceSizes: [320, 480, 640, 750, 828, 1080, 1200, 1920, 2048, 3840],
// https://nextjs.org/docs/basic-features/image-optimization#image-sizes
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
},
} Here's my full implementationimport Head from 'next/head'
import { client } from '../../prismic-configuration'
import Prismic from 'prismic-javascript'
import Listing from '../components/Listing'
//
// Blog Main Page
//
const Blog = (props) => {
return (
<>
<Head>
<title>Blog</title>
</Head>
<div>
<Listing articles={props.articles.results} />
</div>
</>
}
export async function getStaticProps() {
const articles = await client.query(
Prismic.Predicates.at('document.type', 'article'),
{orderings: '[my.article.created desc]', pageSize: 10, page: 1}
)
return {
props: {
articles,
},
}
}
export default Blog //
// Articles Listing Component
//
import PropTypes from 'prop-types'
import {RichText} from 'prismic-reactjs'
import Image from 'next/image'
// data from prismic.io returns the image src as an absolute url, so no need to set up the full url on loader....
const prismicLoader = ({ src, width, quality }) => {
return `${src}?w=${width}&q=${quality || 75}`
}
const Listing = ({ articles }) => {
{articles && articles.map((article) => (
return (
<>
<article key={article.uid}>
<Image
loader={prismicLoader}
src={article.data.article_image.url}
alt={article.data.article_image.alt}
width={article.data.article_image.dimensions.width}
height={article.data.article_image.dimensions.height}
/>
<h5>{RichText.asText(article.data.title)}</h5>
<p>{RichText.asText(article.data.excerpt)}</p>
</article>
</>
)
))}
}
Listing.propTypes = {
articles: PropTypes.array,
}
export default Listing; |
Beta Was this translation helpful? Give feedback.
-
Just use : images: {
It 'll solve Your issue |
Beta Was this translation helpful? Give feedback.
-
Works for me: #18412 (comment) |
Beta Was this translation helpful? Give feedback.
-
I had the same issue, i go to this article which is in Nextjs Docs, |
Beta Was this translation helpful? Give feedback.
-
For folks asking for wildcard, here's my quick solution - I create a shell that puts in the image tag. It doesn't do image optimization, etc, but I can add it if I want to. One nice thing is it clearly calls out in the code when I'm expecting an external image. Necessity is the mother of invention. I too am using google oath, I actually don't want to use a wildecard if it were an option, and I don't want a million domain entries. components/externalImage.js:
Usage:
|
Beta Was this translation helpful? Give feedback.
-
Be sure you are running your tests with |
Beta Was this translation helpful? Give feedback.
-
next.config.mjs:
"Error: Specified images.formats must be length 1 or 2, received length (4), please reduce the length of the array to continue." .. and default eslint config doesn't allow me to use It works if you just ommit "formats" but then what's the point with that then? |
Beta Was this translation helpful? Give feedback.
-
https://nextjs.org/docs/messages/next-image-unconfigured-host here is the answer |
Beta Was this translation helpful? Give feedback.
-
i just remove the prefix url 👍 work for me!!
to |
Beta Was this translation helpful? Give feedback.
-
[SOLVED] for me! @Arthur-bl-dev No need to install dependencies!!! I was trying to use github avatar url. The @miguelseguramx is right! Just remove the protocol (https or http)
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
images: {
domains: ['avatars.githubusercontent.com']
}
}
module.exports = nextConfig
<Image
width={48}
height={48}
src="https://avatars.githubusercontent.com/u/57239907?v=4"
objectFit="cover"
alt="Picture of the author"
className="h-8 w-8 rounded-full"
/> Note: Set the width and height because before I set these properties the image was not showing. |
Beta Was this translation helpful? Give feedback.
-
I had to restart my server after I made changes to |
Beta Was this translation helpful? Give feedback.
-
why is this happening? do you know anything about this?
…On Mon, Jun 13, 2022 at 2:11 AM Douglas Matos da Silva < ***@***.***> wrote:
[SOLVED] for me!
@Arthur-bl-dev <https://github.com/Arthur-bl-dev> No need to install
dependencies!!!
I was trying to use github avatar url.
The @miguelseguramx <https://github.com/miguelseguramx> is right!
Just remove the protocol (*https* or *http*)
next.config.js
/** @type {import('next').NextConfig} */const nextConfig = {
reactStrictMode: true,
images: {
domains: ['avatars.githubusercontent.com']
}}
module.exports = nextConfig
Navbar.tsx
<Image
width={48}
height={48}
src="https://avatars.githubusercontent.com/u/57239907?v=4"
objectFit="cover"
alt="Picture of the author"
className="h-8 w-8 rounded-full"/>
*Note*: Set the width and height because before I set these properties
the image was not showing.
—
Reply to this email directly, view it on GitHub
<#18311 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARCUO3UNZDVGSPIXE2K67K3VOY77HANCNFSM4TB7ZFWA>
.
You are receiving this because you commented.Message ID: <vercel/next.
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
this works for all domains images: { |
Beta Was this translation helpful? Give feedback.
-
Despite the settings mentioned in other answers (I tested new ones After upgrading from |
Beta Was this translation helpful? Give feedback.
-
Can anyone explain why Next.js decided to restrict referencing external images? |
Beta Was this translation helpful? Give feedback.
My bad, just found the answer here: https://github.com/vercel/next.js/blob/canary/examples/image-component/next.config.js