inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

React & Express 를 이용한 웹 어플리케이션 개발하기

Hot Module Replacement | React Hot Loader

react-hot-loader 적용시 에러가 생깁니다.

1173

ooyunjee

작성한 질문수 1

0

ERROR in ./src/index.js Module build failed: Error: React Hot Loader: The Webpack loader is now exported separately. If you use Babel, we recommend that you remove "react-hot-loader" from the "loaders" section of your Webpack configuration altogether, and instead add "react-hot-loader/babel" to the "plugins" section of your .babelrc file. If you prefer not to use Babel, replace "react-hot-loader" or "react-hot" with "react-hot-loader/webpack" in the "loaders" section of your Webpack configuration. at Object.warnAboutIncorrectUsage (/Users/heoyunjee/Desktop/react_fundamentals/node_modules/react-hot-loader/lib/index.js:7:11) @ multi main 서버 실행하면 이런 에러가 뜨는데, 이유와 해결방법을 알려주세요..!

react

답변 10

2

록벨

var webpack = require("webpack");

module.exports = {
  mode: "development",
  entry: "./src/index.js",
  output: {
    path: __dirname + "/public/",
    filename: "bundle.js",
  },
  devServer: {
    hot: true,
    // inline: true,
    host: "0.0.0.0",
    port: 4000,
    static: __dirname + "/public/",
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/,
        options: {
          cacheDirectory: true,
          presets: ["@babel/preset-env", "@babel/preset-react"],
          plugins: ["react-hot-loader/babel"],
        },
      },
    ],
  },
  plugins: [new webpack.HotModuleReplacementPlugin()],
};

-

import React, { Component } from "react";
import { hot } from "react-hot-loader";

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      name: "test",
    };
  }
  render() {
    return (
      <>
        <button
          onClick={() => {
            this.setState({ name: "Veloport" });
          }}
        >
          CLICK ME
        </button>
        <div>Hello! {this.state.name}!!</div>
      </>
    );
  }
}

export default hot(module)(App);

-

{
  "name": "react-fundamentals",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev-server": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "devDependencies": {
    "@babel/cli": "^7.16.0",
    "@babel/core": "^7.16.0",
    "@babel/preset-env": "^7.16.4",
    "@babel/preset-react": "^7.16.0",
    "babel-loader": "^8.2.3",
    "react-hot-loader": "^4.13.0",
    "webpack": "^5.65.0",
    "webpack-cli": "^4.9.1",
    "webpack-dev-server": "^4.6.0"
  }
}

 

1

Codingbear

여러번 삽질 후 webpack 4.x 에서 드뎌~ React, Babel, Sass 번들 환경 구성에 성공했습니다.

물론 react-hot-loader도 설정에 성공했습니다.

참조하실 분은 https://github.com/coddingbear/webpack4_quickstarter/tree/2005-react-hot-loader 함 보세요.

1

김필환

대박송님 처럼 저도 3.0.0 버전에서는 페이지 새로고침이 적용 안되네요.

0

velopert(김 민준)

알고보니 추가적으로 수정해야 할 부분이 있었습니다: https://github.com/velopert/react-codelab-fundamentals/commit/bead4c5438cb8c030ac6cbb59d0c6be2c1074511   react hot loader 3 테스트 할 때 localhost 에서 작업해서 새로고침이 되고있었는지 몰랐습니다 _ _   업데이트의 자세한 내용은 https://github.com/gaearon/react-hot-loader/tree/next-docs/docs#migration-to-30 여기 참고하시면 되겠구요,,   조만간 강의 수정 하도록 하겠습니다.    

0

대박송

강의 감사히 잘보고 있습니다. 저도 위와 같은 문제가 있습니다. react-hot-loader 버전은 3.0.0-beta.3을 사용중인데 HMR 강의에 추가된 내용을 넣어도 페이지가 새로고침이 됩니다. 몇 시간째 삽질하는데 잘 안풀리네요.

0

velopert(김 민준)

HMR 강의에 내용 추가해였습니다 ; )

0

velopert(김 민준)

흠.. 그런지도 모르겠네요! 제가 조만간 한번 알아보도록 하겠습니다.

0

ooyunjee

react-hot-loader 버전이 3.0.0-beta.1로 설치가 되어서 1.3.0으로 바꾸고 nam install 했더니 해결 되었습니다. 버전 문제인가요?

0

ooyunjee

소스를 그대로 복붙했는데도 같은 에러가 나와요..ㅠ

0

velopert(김 민준)

혹시, webpack.config.js 파일에서

loaders: ['react-hot', 'babel?' + JSON.stringify({
cacheDirectory: true,
presets: ['es2015', 'react']
})],
이 부분에 react-hot 대신에 react-hot-loader 라고 적으신건 아닌지요?
만약에 아니라면 - 다음 내용과 비교해보세요..

 

var webpack = require('webpack');

module.exports = {
    entry: './src/index.js',

    output: {
        path: __dirname + '/public/',
        filename: 'bundle.js'
    },

    devServer: {
        hot: true,
        inline: true,
        host: '0.0.0.0',
        port: 4000,
        contentBase: __dirname + '/public/',
    },

    module: {
        loaders: [
            {
                test: /\.js$/,
                loaders: ['react-hot', 'babel?' + JSON.stringify({
                    cacheDirectory: true,
                    presets: ['es2015', 'react']
                })],
                exclude: /node_modules/,
            }
        ]
    },

    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
};

잘 배우고있었는데 ㅠㅠ

0

292

1

react hot reloader

0

191

1

this.props.name할때

0

173

1

시작부터 안됩니다.

1

481

2

초급 유료버전과 차이점은 무엇인가요?

0

338

1

localStorage 강좌에서 componentwillmount 관련 질문입니다.

0

360

1

아무것도 뜨지 않아요

0

567

4

아래 화면에 선생님처럼 Codelab이 안뜹니다. 수업진행이 안되네요

0

510

2

쌤 리액트로 앱 만들수 있는건가요?

0

325

0

babel-preset-stage-0 패키지를 인스톨하여 presets에 stage-0 을 넣자 에러가 발생합니다.

0

312

1

rcc 스니펫 안되시는분들

0

270

0

webpack 5 대응

10

445

2

props의 정의에 대한 질문입니다.

0

377

1

section 4까지 수강 후 프로젝트 완성 후 오류 질문

0

373

1

react.min.js:13 Uncaught TypeError: e.render is not a function

0

346

0

화면에 나오는 코드로 하면 propTypes가 먹히지 않습니다.

0

424

2

메모앱 프로젝트 질문있습니다.

0

229

0

codepen.io 에 퀵에드가 없는데요ㅜㅜ

0

311

1

App.js에서 html 빨간줄

0

288

0

리뉴얼 강좌관련 질문드립니다.

0

261

0

App.js에서 오류가 나네요..

0

261

0

react app과의 port 혼용

1

276

0

Atom으로 예제를 따라하고 있는데 브라우저에 아무것도 나오질 않습니다.

0

343

2

여러개의 smart 컴포넌트를 만들어서 connect할 수 있는건가요?

0

255

0