[英]React Native - Cannot find module X or its corresponding type declarations
[英]Cannot find module 'react' or its corresponding type declarations
今天我將我的 yarn 版本從 1.x 切換到 3.x(最新),我的項目中的 Typescript 開始出現問題。
我見過很多人遇到同樣的問題,但不幸的是,所提供的解決方案都沒有解決它。
這是我當前的 package.json 版本:
{
"name": "project",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"autoprefixer": "10.4.8",
"axios": "0.27.2",
"bcryptjs": "2.4.3",
"dateformat": "5.0.3",
"next": "12.2.4",
"next-auth": "4.10.3",
"next-cookie": "2.8.0",
"next-seo": "5.5.0",
"postcss": "8.4.16",
"qs": "6.11.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "4.4.0",
"sass": "1.54.4",
"sharp": "0.30.7",
"swr": "1.3.0",
"tslib": "2.4.0",
"web-vitals": "2.1.4"
},
"devDependencies": {
"@types/bcryptjs": "2.4.2",
"@types/node": "18.7.14",
"@types/qs": "6.9.7",
"@types/react": "18.0.18",
"@types/react-dom": "18.0.6",
"eslint": "8.21.0",
"eslint-config-next": "12.2.4",
"typescript": "4.7.4"
},
"peerDependencies": {
"react-scripts": "4.0.0"
}
}
即使將@types/react
添加到 devDependencies 我仍然會收到錯誤。 我還嘗試重新啟動 Vscode(和計算機),刪除.yarn-lock
,刪除目錄.yarn
(我不再獲得 node_modules )。 沒有運氣。
看起來 Typescript 正在嘗試查找我正在使用的每個 package 的類型,但其中一些沒有,然后也通過有關它們的錯誤。
在此 Yarn 遷移之前,它曾經運行良好。
有誰知道如何解決? 謝謝!
我認為你應該添加"type": "module
to package.json and "moduleResolution": "node"
to tsconfig.json
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.