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

升级至Next JS 13后出现Cannot read properties of undefined (reading 'and')错误

修复Next.js 13升级后next-transpile-modules导致的构建错误

这个错误的核心原因是**next-transpile-modules与Next.js 13不兼容**,Next.js 13已内置模块转译功能,无需依赖该第三方包。按以下步骤修复:

  • 卸载next-transpile-modules依赖

    npm uninstall next-transpile-modules
    
  • 修改next.config.js配置
    将原来基于withTM的配置替换为Next.js 13内置的transpilePackages选项:
    原配置示例:

    const withTM = require('next-transpile-modules')(['package-a', 'package-b']);
    module.exports = withTM({
      // 其他项目配置
    });
    

    修改后:

    /** @type {import('next').NextConfig} */
    const nextConfig = {
      transpilePackages: ['package-a', 'package-b'],
      // 保留原有其他配置
    }
    module.exports = nextConfig;
    
  • 清理依赖环境并重新安装

    1. 可选:备份当前node_modules和package-lock.json,降低操作风险
    2. 删除旧依赖文件:
      Windows命令:
      rmdir /s /q node_modules
      del package-lock.json
      
      macOS/Linux命令:
      rm -rf node_modules package-lock.json
      
    3. 重新安装依赖:
      npm install
      
  • 验证修复
    运行npm run dev或npm run build,确认构建错误消失。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 12:24:06