tsconfig.json语法检查问题

前言:这个问题卡住好久。全是红色波浪线,代码没法看。

第一步:

"compilerOptions": {
"moduleResolution": "node",
"jsx": "react"
},

解决办法:https://stackoverflow.com/questions/40899868/typescript-cannot-find-module-react

消除了一部分,但一部分还是报错

 

第二步:检查package.json,确实没有react, react-router, umi等。

解决办法:https://bobbyhadz.com/blog/typescript-cannot-find-module-react

# 👇️ with NPM
npm install react react-dom

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

# ---------------------------------------------------

# 👇️ with YARN
yarn add react react-dom

yarn add @types/react @types/react-dom --dev

 

重新安装

# for macOS and Linux
rm -rf node_modules
rm -f package-lock.json
rm -f yarn.lock

# 👇️ clean npm cache
npm cache clean --force

# 👇️ install packages
npm install

 

作者跟我遇到相同问题:

https://stackoverflow.com/questions/64732623/typescript-cannot-find-module-or-its-corresponding-type-declarations

解决办法:

npm install @types/libName // e.g. npm install @types/react-leaflet

 

posted @   走走停停走走  Views(128)  Comments(0Edit  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示