Cant use external next/image with custom server in production
See original GitHub issueBug report
Describe the bug
Cant use external next/image with custom server, request:
http://localhost:3000/_next/image?url=https%3A%2F%2Fpicsum.photos%2Fseed%2F9e56cc3f-be43-4d02-a580-9fe6438640e9%2F208%2F124&w=256&q=75
return 400 and message "url" parameter is not allowed
domain is added to next.config.js and it works in development
To Reproduce
custom server:
const { createServer } = require("http");
const next = require("next");
const { parse } = require("url");
const dev = process.env.NODE_ENV !== "production";
const port = process.env.PORT || 3000;
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
}).listen(port, (err) => {
if (err) throw err;
console.log("> Ready on http://localhost:3000");
});
});
Image component
<Image
src="https://picsum.photos/seed/208/124"
height={124}
width={208}
/>
Expected behavior
Image should load
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: Windows and linux
- Version of Next.js: 10.0.3
- Version of Node.js: 12 and 14
- Deployment: local server and azure
Additional context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Advanced Features: Custom Server - Next.js
A custom Next.js server allows you to start a server 100% programmatically in order to use custom server patterns. Most of the time,...
Read more >next/image does not load images from external URL after ...
I use the Next.js Image component for image optimization. It works great on dev but it doesn't load images from external URLs in...
Read more >Next.js automatic image optimization with next/image
Learn about automatic image optimization and how it can benefit developers with the native, game-changing, and powerful next/image API.
Read more >Best practices to increase the speed for Next.js apps
Using server -side rendering will help your app reduce the time ... Next.js provides an inbuilt next/image component that we can use in...
Read more >Nextjs image optimization with examples - Refine Dev
Built-in image optimization using next image component. ... This is a custom function that resolves external image URLs.
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
Thanks for opening this issue, @gust42.
I can confirm this behavior within a similar setup:
images.domains
is correctly set innext.config.js
"url" parameter is not allowed
in Docker production environmentYou can add a next.config.js to your server folder with your image setup, solved it for me