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

Next.js编译报错:Module not found: Can't resolve 'module'求助

解决方案:Next.js + Wagmi 编译错误(无法解析'module'模块)

以下是针对你遇到的问题的分步解决方法:

  • 检查Next.js与eslint-config-next版本一致性
    eslint-config-next必须和Next.js版本完全匹配,版本不兼容会直接导致模块解析错误。执行以下命令查看版本:

    npm list next eslint-config-next
    

    如果版本不一致,重新安装对应版本,比如安装最新稳定版:

    npm install next@latest eslint-config-next@latest
    
  • 修正next.config.js的fallback配置
    你之前添加的fallback配置可能过度覆盖了Node.js核心模块解析,导致'eslint-config-next'无法找到'module'。正确的配置应该仅针对fs和child_process,且只在客户端环境处理:

    /** @type {import('next').NextConfig} */
    const nextConfig = {
      webpack: (config, { isServer }) => {
        if (!isServer) {
          config.resolve.fallback = {
            ...config.resolve.fallback,
            fs: false,
            child_process: false,
          };
        }
        return config;
      },
    };
    
    module.exports = nextConfig;
    

    注意不要将module加入fallback列表,它是Node.js核心模块,eslint-config-next依赖它完成解析。

  • 彻底清理依赖后重装
    仅清除缓存可能无法解决依赖冲突,执行以下操作彻底重置依赖:

    rm -rf node_modules package-lock.json
    npm install
    
  • 验证Wagmi及相关依赖兼容性
    Wagmi(尤其是v2版本)对Next.js版本有要求,确保你使用的Wagmi、Viem与Next.js版本兼容。更新到最新兼容版本:

    npm install wagmi@latest viem@latest
    
  • 临时禁用ESLint编译检查(紧急方案)
    如果以上方法都无法快速解决,可以临时关闭ESLint的构建时检查,先确保项目能正常运行,后续再排查ESLint配置问题:

    const nextConfig = {
      eslint: {
        ignoreDuringBuilds: true,
      },
      // 保留其他webpack配置
    };
    module.exports = nextConfig;
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 19:26:15