I am trying to implement webpack code splitting in a React-Redux based Javascriptservices project.
So I created an asyncComponent using one of the many samples on the web, and made a simple Contact page load dynamically, like this:
const AsyncContact = asyncComponent(() =>
System.import('./components/Contact').then(module => module.default));
This works, both client-side and serverside.
For a more complex page, with a lot of dependencies, I implemented the same, now with dynamic reducers. and a large Chat component on it. Clientside this page runs without error, but it results in an error when run serverside:
Call to Node module failed with error: TypeError: Converting circular structure to JSON
This error seems to come from here:
https://github.com/aspnet/JavaScriptServices/blob/dev/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js#L78
If I refresh the page, the second time the same page renders succesfully.
I guess my webpack chunk has circular references. I tried to find out which, but I don't know how to debug this. I think Javascript should normally handle circular references, the browser has no problems with it.