You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Specify hostname for chunks from React.lazy during development #12455
Hi, I have a problem with getting code splitting using React.lazy to work during development. The problem is that I'm loading in the generated bundle from a different localhost than the CRA is serving the files from. (localhost:9080 vs localhost:3000). However the chunks are loaded without a specified hostname which results in them being loaded from localhost:9080 instead of localhost:3000. I've tried setting HOST, PORT, and PUBLIC_URL in .env.development. All to no avail.
Is there a way to specify the hostname for the fetched chunks generated by using React.lazy? Thanks for any assistance!
Based on your description I would assume that you have an HTML file served from localhost:9080 similar to the implementation below. Just add the <base> tag along with your derided host:
Activity
GeorgeArgyrousis commentedon Jul 19, 2022
Hey @danielweil, you can fix this issue using the HTML
basetag. This element allows you to specify the base URL all the relative URLs in your document - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/baseBased on your description I would assume that you have an HTML file served from
localhost:9080similar to the implementation below. Just add the<base>tag along with your derided host:The aforementioned implementation will lazy load chuncks with the base path of
http://localhost:3000/.Hope this helps!