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

使用Next.js Image组件时出现TypeError运行时错误求助

解决Next.js Image组件的TypeError: Cannot read properties of undefined (reading 'call')错误

以下是针对该问题的排查和解决步骤:

1. 修复依赖版本冲突

该错误常因Next.js、React或React-dom版本不匹配导致,执行以下命令更新到最新兼容版本:

npm install next@latest react@latest react-dom@latest

2. 检查图片参数与路径

  • 确认width和height设置合理:你当前设置的width={50}、height={10}可能与图片实际宽高比差异过大,建议先替换为图片原始宽高值测试。
  • 验证图片路径:确认../assets/IMG-20221115-WA0001.jpg存在于对应目录,注意Linux/macOS环境下文件名区分大小写。

3. 简化Next.js配置

若你的next.config.js有自定义配置,暂时替换为基础配置测试是否是配置冲突:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
}

module.exports = nextConfig

4. 清除缓存重启服务

执行以下命令清除缓存并重新构建:

rm -rf node_modules .next package-lock.json
npm install
npm run dev

5. 验证组件导出方式

尝试将默认导出改为命名导出测试:

// Header组件内修改导出方式
export function Header() {
  return (
    <header>
        <div>
            <div>
                <Image
                    src={myImage}
                    width={50}
                    height={10}
                    alt="Logo"
                />
            </div>
        </div>
    </header>
  )
}

导入时改为:

import { Header } from './Header'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 06:31:20