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

JSX元素隐式具有any类型错误(TS7026)求助

解决 "JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.ts(7026)" 错误

以下是针对TypeScript 5 + Next.js 13.2 + Chakra UI环境的解决步骤:

  • 检查并修正tsconfig.json配置
    确保编译器选项包含正确的JSX模式和必要类型:

    {
      "compilerOptions": {
        "jsx": "preserve", // 使用App Router时选此项;Pages Router请改为"react-jsx"
        "types": ["next", "react", "react-dom"]
      }
    }
    
  • 重新安装核心类型依赖
    执行命令补充或修复@types/react和@types/react-dom:

    npm install --save-dev @types/react @types/react-dom
    
  • 验证Chakra UI依赖兼容性并重装
    确保Chakra UI版本与Next.js 13.2兼容(推荐2.5.0+),执行重装命令:

    npm install @chakra-ui/react @emotion/react @emotion/styled framer-motion
    
  • 重启TypeScript语言服务
    在VS Code中按Ctrl+Shift+P(Windows)/Cmd+Shift+P(Mac),选择「TypeScript: Restart TS Server」清除类型缓存。

  • 确认文件后缀正确性
    所有包含JSX语法的文件必须使用.tsx后缀,而非.ts。

补充:确保Head组件正确导入
你的代码中使用的Head是Next.js内置组件,需先导入:

import Head from 'next/head';

// 组件内使用
<Head>
  <title>Real Estate API Application</title>
  <meta name="description" content="Generated by create next app" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <link rel="icon" href="/favicon.ico" />
</Head>

内容的提问来源于stack exchange,提问作者Mirza Mahad Baig

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 01:07:24