Closed netergart closed 9 months ago
i have the same issue on 14.0.1 with custom server
14.0.3
Same issue
If it help, on production we have specific route, for example it's /collections/<collection>/image
, this route handled by nginx and proxied to backend (not nextjs) that return a file.
14.0.4
Same issue. The only idea that comes up how to fix this is to simply add the origin before the image path.
I came up with a solution. In general, I decided to replace the urls in the file itself server.js Which seems logical.
// server.js
const { createServer } = require('http');
const { parse } = require('url');
const next = require('next');
const dotenv = require('dotenv');
dotenv.config({ path: `.env` });
const dev = process.env.NODE_ENV !== 'production';
const ORIGIN = process.env.ORIGIN
const hostname = 'localhost';
const port = process.env.APP_PORT || 3000;
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer(async (req, res) => {
try {
const parsedUrl = parse(req.url, true);
let newParsedUrl = parsedUrl
if (parsedUrl.pathname === '/_next/image') {
const newSearch = new URLSearchParams({
...parsedUrl.query,
url: `${ORIGIN}${parsedUrl.query.url}`,
}).toString()
newParsedUrl = parse(`${parsedUrl.pathname}?${newSearch}`)
}
await handle(req, res, newParsedUrl);
} catch (err) {
console.error('Error occurred handling', url, err);
res.statusCode = 500;
res.end('internal server error');
}
}).listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://${hostname}:${port}`);
});
});
hostname
but this will not work if you use images from other sources, I mean if you use local and remote images together from other domain
Bumping this as I am facing the same issue
Got this once in v13's development, now it just happens to some sizes of the same image once I deployed the app using a custom server to cPanel.
Same issue here! I found a solution which is don't import the image, but add it to public and import it via URL, though it is not an ideal solution
I am also facing the same issue. In my case upstream image response failed for https://imageurl
is infinitely showing in server logs. Even I handle a placeholder image inside onError callback, it soesn't show up and image caught flashing forever.
https://github.com/vercel/next.js/assets/87934366/28c3c443-02f2-45f7-9a6b-5dff73bc4466
Thanks for reporting this issue!
This was fixed in PR https://github.com/vercel/next.js/pull/61471 and will be available in a future stable release.
You can try it out today on the canary channel with npm i next@canary
, thanks!
I can confirm that this is fixed in the latest canary version for me using a custom server with SSL.
@styfle, is there an easy way to track when this fix will get incorporated into a future stable release? Will this issue be mentioned in the release notes or something like that?
@thepuzzlemaster Yes, each release includes which PRs are included in the release.
View releases for this repo here: https://github.com/vercel/next.js/releases
You can also subscribe to new release notifications using by clicking "Watch", then "Custom", then "Releases", then "Apply" at the top of the repo.
So is this fix not in the stable version yet?
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Link to the code that reproduces this issue
https://github.com/netergart/nextjs-example/blob/main/apps/web/app/page.tsx#L137
https://github.com/netergart/nextjs-example/blob/main/apps/web/server.js
To Reproduce
Current vs. Expected behavior
when run without a custom server everything works correctly. But with the custom server, I have an issue
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Image optimization (next/image, next/legacy/image)
Additional context
I tested with the last canary and have this issue too
https://github.com/vercel/next.js/issues/53715 people wrote the same but the issue is closed.
If you run
next dev
and thennode server.js
images are loaded because they are already processedthis issue only with format not equal
svg