[英]Unable to create React project using create react app
所以我正在嘗試學習 React,按照https://reactjs.org/docs/create-a-new-react-app.html上的說明進行操作。 具體來說,我正在使用 Create React App,但碰巧遇到了一個錯誤:
Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: test-react@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR! react@"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"<18.0.0" from @testing-library/react@12.1.5
npm ERR! node_modules/@testing-library/react
npm ERR! @testing-library/react@"^12.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
從我在這里看到的情況來看,測試庫要求安裝的 React 版本低於 18.0.0,但 Create React App 只是自動安裝最新的 React 版本,從而導致錯誤。
我該如何解決這個問題? 如前所述,我是一個完全的新手,所以非常感謝任何幫助。
在暫時解決此問題之前,您可以刪除node_modules
文件夾和package-lock.json
。
接下來,打開package.json
並將"react": "^18.0.0"
& "react-dom": "^18.0.0"
更改為早期版本,例如"react": "^17.0.2"
& "react-dom": "^17.0.2"
。
最后,可以運行npm install
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.