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

部署至Netlify时构建失败,本地无异常求技术支持

问题解决:Netlify部署Next.js项目失败(本地构建运行正常)

错误核心原因

从构建日志可明确判定:pages/components/Instagram.jsx组件中引用图片时,使用了本地机器的绝对路径(例如/Users/santiagoramirez/landing_githubpages/public/hhh.png),而Netlify的远程构建环境不存在该路径,导致webpack无法找到图片文件,最终构建失败。

修复步骤

  1. 打开项目中的pages/components/Instagram.jsx文件
  2. 替换所有图片引用路径:
    • 直接使用根相对路径:由于图片存放在项目根目录的public文件夹下,只需将路径改为/hhh.png、/img100.png这类以/开头的格式(Next.js会自动映射到public目录)
    • 或采用import导入方式:比如import hhhImg from '../../../public/hhh.png',之后在组件中通过src={hhhImg}使用图片
  3. 提交修改后的代码至仓库,重新触发Netlify构建

本地验证建议

修改完成后,先在本地执行构建命令确认无问题,再推送代码部署:

yarn build

关键错误日志片段

2:10:26 PM: ./pages/components/Instagram.jsx
2:10:26 PM: Module not found: Can't resolve '/Users/santiagoramirez/landing_githubpages/public/hhh.png' in '/opt/build/repo/pages/components'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 05:15:26