react 问题合集

创建时出错

出现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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值