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 @ 2023-07-11 22:07  走走停停走走  Views(110)  Comments(0Edit  收藏  举报