You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js 13通过GitHub部署后图片无法加载(404错误)

Next.js 13 部署至GitHub后图片404问题求助

我用Next.js 13开发的网站部署到GitHub后,所有图片均无法加载,服务器返回404错误,但本地执行npm run dev运行或npm run build构建后,网站图片显示完全正常。

已完成的排查步骤:

  • 验证图片路径:确认图片存放于public文件夹,使用的相对路径无误;
  • 检查图片格式:采用PNG、JPG等next-images插件支持的常见格式;
  • 配置图片域名:已在next.config.js的images配置项中添加相关外部域名;
  • 验证图片导入:检查组件内图片导入方式,确认源地址正确;
  • 清除缓存资产:多次清除浏览器缓存,排除缓存导致的问题;
  • 检查部署流程:确认部署操作正确,所有图片文件已包含在部署包内。

尽管完成以上所有排查步骤,问题仍未解决,生产环境下图片依旧返回404错误。

附next.config.js配置代码:

/** @type {import('next').NextConfig} */
const withFonts = require('next-fonts');
const withImages = require('next-images'); // Import next-images plugin

const nextConfig = {
  experimental: {
    appDir: true,
  },
  // Add the images configuration for image formats
  // This will support PNG, JPG, JPEG, GIF, and SVG formats
  images: {
    domains: [], // Add any domains if you are using external image URLs
  },
  output: 'export',
};

module.exports = withFonts(withImages(nextConfig)); // Add withImages to the chain

内容的提问来源于stack exchange,提问作者Elon Abergel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 01:03:24