-
Notifications
You must be signed in to change notification settings - Fork 27.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image optimisation external resource not working #18412
Comments
|
Did you restart You should see a message that says "Restart the server to see the changes in effect" when you change next.config.js and the server is running. With CodeSandbox, I had to click "Restart Server" in the left menubar. |
I got this issue after deploying Next.js app to firebase hosting with firebase functions.. |
@mshahzaib101 did you find any solution? Image works fine on local but fails after deployment. In my case I deployed to GAE. |
@dipesh429 no man, didnt get the solution yet.. |
@mshahzaib101 It did work on my project finally. The problem was to include 'domain' in next.config.js. Link. For me I have a lerna project setup, so I had next.config.js for each project and one next.config.js on the root as well. I previously had included 'domain' on each projects's next.config.js. But I actually need to put it in the root next.config.js. |
I'm having the same issue when trying to display an avatar image from GitHub. Local it works: On my production deploy it doesn't:
My module.exports = {
images: {
domains: [
'avatars3.githubusercontent.com',
'[my private URL]'
],
}, |
@raphaelbs I had a similar issue, in that it worked locally but not in prod, and it turned out my |
That was it @badsyntax, thank you! |
As far as I understand, nextjs optimize images wrapped by Might need to split |
Just to share what happened in my case. I assigned a base URL (together with protocol) instead of a hostname (without protocol)
Changing |
Just to share my case too. on images: {
domains: ["images.example.com"],
}, i didn't add then on the Image component: I used the import Image from 'next/image'
const myLoader = ({ src, width, quality }) => {
return `https://images.example.com/${src}?w=${width}&q=${quality || 75}`
}
const MyImage = (props) => {
return (
<Image
loader={myLoader}
src="/me.png"
alt="Picture of the author"
width={500}
height={500}
/>
)
} At first, i just tried putting the image url on the |
One thing I'd like to add to @badsyntax's comment is that the So for a Docker setup, especially if it's a multi-stage build configuration, make sure that the |
just removing protocol fixed the issue for me :) |
I want to share my case. If you use docker and refer to official docs from nextjs https://nextjs.org/docs/deployment#docker-image |
For anyone running into this on Netlify, add the domains as an env variable 'NEXT_IMAGE_ALLOWED_DOMAINS'. Theres a note about it in the deploy script, but no error is thrown so it's not obvious you'd need to look there. |
@maurusrv if you use a custom loader on the Image component then none of the images.domains configuration in next.config.js matters. |
Did anyone ever end up figuring this out for Firebase. Images are not loading even for a |
So I found an issue with Firebase functions. I think Next is attempting to write to an unwritable directory, so that's why it's having 500 errors. It has nothing to do with the image being external or internal. |
good to know @wereHamster. i could just remove the line in my next config then. |
here to share my expirience too, i have a nodejs server to save/serve images to nextjs app, and i have a rewrite to force https and www, so in nextjs config if your webserver force redirect to www you need to add it too since it's a subdomain. |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
When optimising images from external sources I get the following error in production:
To Reproduce
Images are coming from:
images.example.com
next.config.js has:
Expected behavior
The images should also be optimised in production/ from an external source.
Inside the PR for optimised images (https://github.com/vercel/next.js/pull/17749/files)
You can see where the error comes from but I am not sure why it is thrown, I am using a custom server but should not be a problem since it seems to work locally.
I added some logging to the code to check the inputs but based on this I do not find anything that would suggest
!domains.includes(hrefParsed.hostname)
this line would turntrue
The text was updated successfully, but these errors were encountered: