React 19 HMR: странные баги в hello-world проекте

Первая проблема: Ошибка появляется перед перезагрузкой страницы сразу после того, как я делаю изменения в файлах.

enter image description here

Вторая проблема: HMR обновляет страницу, вместо внесения изменений в простейший компонент (App).

./package.json:

{
  "name": "chat-contests",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "dev": "npx webpack serve",
    "build": "npx webpack"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "@babel/core": "^7.26.0",
    "@babel/preset-env": "^7.26.0",
    "@babel/preset-react": "^7.26.3",
    "babel-loader": "^9.2.1",
    "css-loader": "^7.1.2",
    "html-webpack-plugin": "^5.6.3",
    "style-loader": "^4.0.0",
    "webpack": "^5.97.1",
    "webpack-cli": "^6.0.1",
    "webpack-dev-server": "^5.2.0"
  },
  "dependencies": {
    "@reduxjs/toolkit": "^2.5.0",
    "axios": "^1.7.9",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "react-redux": "^9.2.0"
  }
}

./src/index.js:

В логи пишется только сообщение "HOT AVAILABLE". По какой-то причине колбек из module.hot.accept не вызывается.

import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';

const app = createRoot(
    document.getElementById('app')
);

const render = () => app.render(<App />);

if (module.hot) {
    console.error('HOT AVAILABLE');
    
    module.hot.accept('./App', () => {
        console.error('HOT ACCEPTED');

        const NextApp = require('./App').default;
        
        console.error('HOT APP LOADED');
        
        app.render(<NextApp />);
    });
} else {
    console.error('NOT HOT');

    render();
}

./src/App.js:

import React from 'react';

const App = () => {
    return (
        <div>Hello World!!10!</div>
    );
};

export default App;

./webpack.config.js:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    mode: 'development',
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.[contenthash].js',
        clean: true
    },
    devServer: {
        static: {
            directory: './dist',
            publicPath: '/apps/chat-contests/dev'
        },
        port: 1010,
        hot: true,
        allowedHosts: 'all',
        client: {
            webSocketURL: {
                protocol: 'wss',
                port: 443,
                hostname: 'my-hostname.com',
                pathname: '/chat-contests-ws'
            }
        }
    },
    module: {
        rules: [{
            test: /\.jsx?$/,
            exclude: /node_modules/,
            use: 'babel-loader'
        }, {
            test: /\.css$/,
            use: [ 'style-loader', 'css-loader' ]
        }]
    },
    resolve: {
        extensions: [ '.js', '.jsx' ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html'
        })
    ]
};

Если я прописываю в файл следующие изменения, то HMR обновляет контент компонента App без перезагрузки страницы, но я всё также продолжаю получать эти ошибки:

./src/index.js:

import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';

const app = createRoot(
    document.getElementById('app')
);

const render = () => app.render(<App />);

render();

if (module.hot) {
    module.hot.accept();
}

enter image description here


Ответы (0 шт):