【问题标题】:React app server wont restart automatically using create react appReact app 服务器不会使用 create react app 自动重启
【发布时间】:2020-12-23 12:23:44
【问题描述】:

我正在使用 create-react-app 制作一个简单的应用程序
但是服务器停止并且不会更新更改
请帮忙

npm 版本 6.14.4
节点版本 10.19.0
Ubuntu 20.04 LTS
WSL 2 Windows 10 家庭版\

我的 Index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

serviceWorker.unregister();

我的 app.js

import React from 'react';
import Palette from './Palette';
import seedColors from './seedColors'
import './App.css';

function App() {
  return (
    <div className ="App">
      <Palette colors ={seedColors[3]}/>
    </div>
  );
}

export default App;

我的调色板.js

 import React, { Component } from "react";

 class Palette extends Component{
     render(){
         return(
             <div><h1>Palette</h1></div>
         )
     }
 }

 export default Palette

seedColors.js,我取自https://github.com/Colt/react-colors/blob/master/colors-app/src/seedColors.js

【问题讨论】:

    标签: node.js reactjs create-react-app babeljs webpack-dev-server


    【解决方案1】:

    尝试将.env 文件添加到您的根项目目录(其中有package.jsonnode_modules)。然后在.env 中添加CHOKIDAR_USEPOLLING=true。当我遇到热重新加载不起作用的问题时,这对我有用。显然,“观察者”在使用 VM(如 WSL)时需要此设置。我在这里的最佳答案中发现了这个推荐:React create app hot reload is not always working on linux

    【讨论】:

    • 谢谢,这真的帮助了我..它现在正在工作
    • @ASHUTOSHSINGH,很高兴为您解决问题!您能否支持我的回答并标记为已接受?我目前只有 1 个声望,我将不胜感激。
    猜你喜欢
    • 2021-02-22
    • 2018-05-01
    • 2017-09-02
    • 2018-07-16
    • 2018-01-30
    • 2019-05-30
    • 1970-01-01
    • 2018-04-21
    • 2019-10-30
    相关资源
    最近更新 更多