我通过以下方式创建了一个新的 Vite Typescript + SWC React 项目:
yarn create vite@latest my-app-name
。
之后,我用
yarn
安装了依赖项。
查看默认样板时,例如
main.tsx
,我收到很多 TS 错误,例如:
Cannot find module 'react/jsx-runtime' or its corresponding type declarations.ts(2307)
当鼠标悬停在 <React.StrictMode>
上时
或
Cannot find module 'react/jsx-runtime' or its corresponding type declarations.ts(2307)
将鼠标悬停在 <App />
上时。
我尝试通过
yarn add @types/react -D
添加类型,确认它在我的开发依赖项中,重新启动我的 TS 服务器,重新启动 VSCode,重新启动开发服务器,并确认我的 "jsx": "react-jsx"
中有 tsconfig
,但我仍然有这些错误.
如何解决这些 Typescript 问题?
我在使用yarn v4和vite时遇到了同样的问题....