我刚刚发现了 React。我想安装最新稳定版本的 React (17.0.2),但无法基于 React 17 创建新项目。
你能帮助我吗?
$] npm --version
8.5.5
$] node --version
v16.15.0
Run Code Online (Sandbox Code Playgroud)
我尝试了版本 18,但我想要使用的许多依赖项对于版本 18 来说不是最新的。
我做了以下事情:
$] npx create-react-app sample-11
$] cd sample-11
$] cat package.json
{
"name": "sample-11",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Run Code Online (Sandbox Code Playgroud)
然后我更新了 package.json,将 18.1.0 替换为 17.0.2。我更新这一行:
"react": "^17.0.2"
"react-dom": "^17.0.2"
rm -rf node_modules
rm package-lock.json
npm install
Run Code Online (Sandbox Code Playgroud)
我收到错误:
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from @testing-library/react@13.2.0
Run Code Online (Sandbox Code Playgroud)
因此,我通过删除“@testing-library/react”来更新 package.json
npm install
Run Code Online (Sandbox Code Playgroud)
好的。
npm start
Compiled with problems:
ERROR in ./src/index.js 5:0-40
Module not found: Error: Can't resolve 'react-dom/client' in '/home/dev/Projets/node-projects/sample-11/src'
Run Code Online (Sandbox Code Playgroud)
Ahm*_*ler 14
创建新项目后,在 package.json 中我们更新这一行
"react": "^17.0.2"
"react-dom": "^17.0.2"
Run Code Online (Sandbox Code Playgroud)
然后删除package-lock.json和node_modules然后应用
npm install
Run Code Online (Sandbox Code Playgroud)
小智 7
尝试这样
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"typescript": "^4.7.4",
"web-vitals": "^2.1.4"
Run Code Online (Sandbox Code Playgroud)
},
归档时间: |
|
查看次数: |
21738 次 |
最近记录: |