CORS Error when fetching images (maybe only when image comes from AWS)
See original GitHub issueWhat version of Next.js are you using?
10.0.2
What version of Node.js are you using?
14.16.1
What browser are you using?
Firefox and Chrome
What operating system are you using?
Ubuntu
How are you deploying your application?
next start
Describe the Bug
The new version of Next seems to be having problems with CORS. I think this error, for some reason I couldn’t figure out, only happens when the image comes from AWS.
Expected Behavior
To check the expected follow these steps:
- Create a new package
yarn create next-app bug-next-demo
- In pages/index.js, place this content:
import Image from 'next/image'
export default function Home() {
return (
Image src="https://assets.instabuy.com.br/ib.store.image.medium/m-99852d734ad2478aa05dfeff49e29085.png" width={60} height={60} />
)
}
- Set the
next.config.js
.
module.exports = {
images: {
domains: [
'assets.instabuy.com.br',
]
}
}
- Change the next version to 10.0.9
// package.json
"dependencies": {
"next": "10.0.9"
}
- After installing the dependencies, and running them on the index page you will check this in your web browser:
To Reproduce
To reproduce, you just need to update next package to 10.2.0 from the expected behavior scenario, as follows:
"dependencies": {
"next": "10.2.0",
}
Now, just re-run the installation and the development execution on the index page of the browser. You will check the following CORS error:
Note:
This image comes from AWS. It doesn’t seem to happen from other sources.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Troubleshooting CORS - Amazon Simple Storage Service
If you encounter unexpected behavior while accessing buckets set with the CORS configuration, try the following steps to troubleshoot:.
Read more >fetching images from Amazon s3 gives CORS error. (Chrome ...
and the error I receive is : Image from origin 'https://s3.amazonaws.com' has been blocked from loading by Cross-Origin Resource Sharing policy: ...
Read more >Dealing with image CORS error in Chrome, Chromium and ...
The issue comes from the way that Chromium caches the images. The way that the initial image is cached is - without the...
Read more >How to solve S3 CORS file error with "Access-Control-Allow ...
Did you upload a file to S3 to power your web application or visualization, and now it just won't work? Let's figure out...
Read more >CORS is still getting error - Images - Cloudflare Community
Someone need to fix Cloudflare Image CORS issue, it's been a while and no one help us. Cloudflare Images CORS error.
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
I don’t think this is a bug. It is not related to the CORS issue.
If you refer to this file at line 193 you can see that a new condition was added to check for the content type header of a response.
After checking the link for the image you provided, the
Content-Type
header provided by the image isbinary/octet-stream
and not animage/png
as I believe it is required to be to use the Image module provided by Next.js.In order to fix it, for your S3 bucket change Content-Type of the image your are providing to image and I believe it should work fine 😃
Hopefully that helps!
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.