JSX.Element 这里报找不到JSX命名空间?

来源:5-7 【主页开发】热门产品推荐

linda89757

2025-03-28

https://img1.sycdn.imooc.com/szimg/2b13696708e6b25313000969.jpg


老师,JSX.Element  这里报找不到JSX命名空间?这个什么情况?怎么你没报错啊?

写回答

1回答

阿莱克斯刘

2025-03-29

你的情况确实有点奇怪,不过“找不到命名空间 'xxx'”,这种情况通常与 TypeScript 的配置有关,可能是缺少 JSX 支持。TypeScript 需要指定 `jsx` 编译选项,以支持 React 相关的 JSX 语法。

确保你的 `tsconfig.json` 文件中有正确的配置:

   ```json
   {
     "compilerOptions": {
       "jsx": "react", // 或者 "react-jsx" (React 17+ 推荐)
       "esModuleInterop": true, // 确保模块互操作性
       "allowSyntheticDefaultImports": true
     }
   }
   ```

然后,检查你的 TypeScript 版本,保你使用的是支持 JSX 的 TypeScript 版本(至少 4.1 或更高版本)。

试试看这些步骤能否解决问题。如果问题依旧,你可以查看一下课程的代码库,代码库有源码,可以对比查看一下是哪里不一样。
0
1
linda89757
```json { "compilerOptions": { "target": "es5", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "plugins": [ { "name": "typescript-plugin-css-modules" } ] }, "include": [ "src" ] } ```
2025-03-29
共1条回复

React18 系统精讲 结合TS打造旅游电商平台

React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能

2008 学习 · 1024 问题

查看课程