解决这个问题
Failed to resolve import "react-dom/client" from "srcmain.jsx". Does the file exist?
这是我的主要。jsx文件
import React from 'react'
import ReactDOM from 'react-dom/client'
// import {render} from "react-dom";
import App from './components/App.jsx'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
我也试过这样做
import React from 'react'
import {render} from "react-dom";
import App from './components/App.jsx'
import './index.css'
const container = document.getElementById("root");
render(
<React.StrictMode>
<App />
</React.StrictMode>,
container
);
但是这个显示空白页
如果有人能帮忙,请看看这个
我正在尝试使codependency复制项目这些是我在package .json
中的依赖项"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.31",
"@fortawesome/free-brands-svg-icons": "^5.15.0",
"@fortawesome/free-solid-svg-icons": "^5.15.0",
"@fortawesome/react-fontawesome": "^0.1.11",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"codemirror": "^5.58.1",
"react": "^16.13.1",
"react-codemirror2": "^7.2.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3"
},
而不是:
import App from './components/App.jsx'
写:
import App from './App';
它对我有效。
运行"npm "它将解决这个错误,因为当您手动安装deps时,似乎缺少了一些依赖项。