question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chunks exist in my stats file but not in LOADABLE_REQUIRED_CHUNKS on client.

See original GitHub issue

I have been trying the last few days to get code splitting working with SSR and after fixing a bunch of webpack/babel related issues (upgrading to webpack v4 & babel v7 with updated babel plugins), I am now facing an issue with the ChunkExtractor and loading of links/scripts.

In my routes file I have a loadable component

const Discover = loadable(() => import('../pages/discover.js'));

and I am seeing the the chunkName in my stats-loadable.json

"assetsByChunkName": {
    "main": [
      "main.d1605868d5f74e36b617.css",
      "main.d1605868d5f74e36b617.js"
    ],
    "pages-discover": "pages-discover.271ab8a69db56a13d8d5.js"
  },

But after running the example code from the documentation for the ChunkExtractor, I’m still not seeing the “pages-discover” chunk in the DOM when server side rendering. The weird part is that I am seeing the main chunk being rendered though.

<script>window.__LOADABLE_REQUIRED_CHUNKS__ = [];</script>
<script async data-chunk="main" src="/static/main.d1605868d5f74e36b617.js"></script>

Here is the relevant server code I’m using for SSR:

 const AppComponent = () => (
          <ApolloProvider client={client}>
            <Provider store={store}>
              <I18nextProvider i18n={req.i18n}>
                <AppDelegate>
                  <StaticRouter location={req.url} context={context}>
                    <Route component={props => <Routes {...props} />} />
                  </StaticRouter>
                </AppDelegate>
              </I18nextProvider>
            </Provider>
          </ApolloProvider>
        );

const webExtractor = new ChunkExtractor({
          statsFile: webStats,
        });

        const jsx = webExtractor.collectChunks(<AppComponent />);

        let initialState = {};

        try {
          await getDataFromTree(jsx);
          initialState = client.extract();
        } catch (e) {
          console.log('catching getDataFromTree');
        }

        const html = renderToString(jsx);

        const scriptTags = webExtractor.getScriptTags();

        const linkTags = webExtractor.getLinkTags();

        const styleTags = webExtractor.getStyleTags();

Then I pass all these variables to a render function to load the content that is sent to the user.

Any help or insight would be much appreciated!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
garrettshermcommented, Jul 30, 2019

@zhoushuanglong Sorry for the late response but I solved my issue a while back, and like @neoziro said it had to do with my webpack config being wrong. Instead of using @loadable/component as an external I was using @loadable/server (see https://github.com/smooth-code/loadable-components/blob/master/examples/server-side-rendering/webpack.config.babel.js).

Once I changed that it worked. Hope that can you help you out.

0reactions
gregbergecommented, May 17, 2019

The library is stable and widely used, if you experience this issue, it is probably a wrong setup.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chunks exist in my stats file but not in ... - GitHub
I have been trying the last few days to get code splitting ... Chunks exist in my stats file but not in LOADABLE_REQUIRED_CHUNKS...
Read more >
Loadable Components SSR - chunkNames in Server Stats file ...
I'm using Craco to override Webpack config and it seems to be working, as the client side loadable-stats.json is being generated. When I...
Read more >
Server Side Rendering - Loadable Components
This is the stats file generated by webpack loadable plugin. const statsFile = path.resolve(' ... The collectChunks method wraps your element in a...
Read more >
Manage Chunks in a Sharded Cluster — MongoDB Manual
This page describes various operations on chunks in sharded clusters. MongoDB automates most chunk management operations. However, these chunk management ...
Read more >
优化 | webpack
You may have split the app into multiple chunks, which are loaded at your router. The entry chunk only contains the router and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found