timarney / react-app-rewired

Override create-react-app webpack configs without ejecting
MIT License
9.76k stars 425 forks source link

Trouble to start the dev server #630

Open GuyoST opened 1 year ago

GuyoST commented 1 year ago

Hello every one,

I just installed and configured react-app-rewired, thank you so much because I could split my code as I wanted to.

I had no problem to build the app using npm run build (react-app-rewired build).

But when I try npm start using react-app-rewired start, it stucks on "Starting the development server" and if I try to connect on http://localhost:3000, I get an infinite "pending" on "localhost".

My configuration is working without any trouble when I want to build, I get the app splitted as I wanted and it's working in production.

Here is the configuration if it can helps (just to get one chunk per node_module) :

module.exports = {
    webpack: function override(config, env) {

        config.optimization.runtimeChunk = 'single'

        config.optimization.splitChunks = {
            chunks: 'all',
            maxInitialRequests: Infinity,
            minSize: 0,
            cacheGroups: {
                vendor: {
                    test(module) {
                        return !!module.context && module.context.includes("node_modules")
                    },
                    name(module) {
                        const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
                        return `npm.${packageName.replace('@', '')}`;
                    }
                }
            }
        }

        return config;
    },

    devServer: function (configFunction) {

        return function (proxy, allowedHost) {
            const config = configFunction(proxy, allowedHost);
            return config;
        };
    },
}

I tried to use react-scripts for npm start and it starts correctly, but I think of course it ignores my code splitting configuration.

So I honestly have no idea if that comes from this react-app-rewired or not, but I post here in case it can help to find a solution for me and for other people who can be in the same situation ?

If you have any advice to get more details to know why it stucks (how to get logs ? or something ?) I would be happy ! If you need more details, just ask me 🙂

I'm using for this project : react 17 and react-script 5.0.1

Thank you

KoreSamuel commented 1 year ago

the same issue occurred in my project.

lll000111 commented 10 months ago

From the README, check out section "3) Webpack Dev Server"

I hate that section because I have no idea what it is trying to say (why not just give instructions for what to do?), but in any case, I think that section is trying to say that the rewired functionality is not used for dev builds. Unfortunately their instructions for what to do are undecipherable for me (unwilling to put in a day or more of work to find out what they mean, they could just have given simple instructions, no?).