Loadable-components: "cannot find main in stats"

Created on 9 Dec 2018  路  6Comments  路  Source: gregberge/loadable-components

I'm getting a "cannot find main in stats" issue. I would like to have more info as to what this error is about. I follow the sever side rendering guide and my current code set up is this

    const statsFile = path.resolve("./build/server/loadable-stats.json");
    const extractor = new ChunkExtractor({ statsFile });

    // Declare our React application.
    const app = extractor.collectChunks(
        <JssProvider registry={sheetsRegistry} jss={jss} generateClassName={generateClassName()}>
            <MuiThemeProvider theme={theme} sheetsManager={new Map()}>
                <Provider store={store}>
                    <StaticRouter location={request.url} context={reactRouterContext}>
                        <Application />
                    </StaticRouter>
                </Provider>
            </MuiThemeProvider>
        </JssProvider>
    );
    const appString = renderToString(app);
    const scriptTags = extractor.getScriptTags(); // or extractor.getScriptElements();
    console.log(scriptTags);

This is the error screenshot
image

Most helpful comment

got it! it was const extractor = new ChunkExtractor({ statsFile, entrypoints: ["index"] });

All 6 comments

got it! it was const extractor = new ChunkExtractor({ statsFile, entrypoints: ["index"] });

I love happy ends 馃榿

But my suffering persists. What should these entrypoints render? Name of entry in webpack config? or what

Answering myself: yes, this is the name of your webpack entry e.g.: app like in:

entries: { app: path.resolve(__dirname, '..', 'src/index.tsx') }

Not sure if this is the right thread to ask my question, but gonna give it a try anyway:

It looks like my @loadable/webpack-plugin sometimes skips chunks. On the server side I need the ChunkExtractor({ entrypoints: ["server"] }. When I run a build the server.js chunk does not exist inside the loadable-stats.json.

That said, I tried a few things:

  • remove the entrypoints option from the chunkExtractor (this caused the server.js file to appear in loadable-stats.json once)
  • ran 5 builds with the exact same configuration (this also caused the server.js file to appear in loadable-stats.json once or twice but very randomly)

What I think might be wrong:

  • Async issue? Webpack is not done doing it's magic before @loadable/webpack-plugin kicks in ?

Any help is appreciated

@bramvdpluijm you should provide a complete repository example and open a new issue.

i'm a bit confused as well, is this the entry point for your server code, or the client code?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yanv1991 picture yanv1991  路  4Comments

mschipperheyn picture mschipperheyn  路  5Comments

gcardella picture gcardella  路  7Comments

bitttttten picture bitttttten  路  8Comments

zzyxka picture zzyxka  路  7Comments