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

使用react-dom/client出现TS7016错误:找不到模块声明文件

解决React DOM Client的TS7016类型声明错误

错误信息

Compiled with problems:X

ERROR in src/index.tsx:2:28

TS7016: Could not find a declaration file for module 'react-dom/client'. 'C:/Users/Mohamad/Desktop/HIS/Administration/Administration/Administration/Administration.Endpoints.WebUI/ClientApp/node_modules/react-dom/client.js' implicitly has an 'any' type.
Try npm install @types/react-dom if it exists or add a new declaration (.d.ts) file containing declare module 'react-dom/client';
1 | import * as React from 'react';

import { createRoot } from 'react-dom/client';
^^^^^^^^^^^^^^^^^^
import App from './App';
5 |

解决方案

方法1:安装官方类型声明包

执行命令安装@types/react-dom:

npm install @types/react-dom --save-dev

使用Yarn的话:

yarn add @types/react-dom --dev

安装完成后重启开发服务器或重新编译项目,错误即可解决。

方法2:手动添加声明文件

若安装类型包无效,可手动创建声明文件:

  • 在项目src目录下新建react-dom-client.d.ts文件
  • 写入以下内容:
declare module 'react-dom/client';

保存后TypeScript会自动读取该声明,消除类型报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 16:50:45