创建时出错
出现You are running create-react-app
4.0.3, which is behind the latest release问题
解决方法:
npm uninstall -g create-react-app
然后清空
npx clear-npx-cache
最后再重新启动
npx create-react-app myapp
启动时出错
当最后显示200,表示之前的操作成功。在进行下一步操作
cd myapp
npm start
此时遇到问题
Module not found: Error: Can’t resolve ‘web-vitals’ in ‘/Users/myapp/src’
从本地路径进入src包中的index.js
把import reportWebVitals from './reportWebVitals';
注释掉,整体如下:
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
//import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
解决完,出现以下代码,成功:
You can now view myapp in the browser.
Local: http://localhost:3000
On Your Network: http://172.20.10.2:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
webpack compiled successfully