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.

Code splitting in library mode causes undefined component import

See original GitHub issue

Bug report

What is the current behavior? When code splitting used (common chunk usage) imported component resolved as undefined. I don’t want to include shared code in each component import but i cannot achieve this with chunks or dependOn.

Library module import without code splitting without_chunks

Library module import with code splitting chunks_issue

If the current behavior is a bug, please provide the steps to reproduce. Repository to reproduce: https://github.com/xleepy/webpack-library-code-splitting

What is the expected behavior? Module should not return undefined module in case common chunk used (at least i hope)

Other relevant information: webpack version: 5.75.0 Node.js version: v18.12.1 Operating System: Xubuntu 22.04.1/macOS Additional tools:

Thanks for any suggestion!

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Nov 28, 2022

@xleepy I recommend bundle (or even more - don’t bundle at all) icons as a separate library and put in TODO how to use them, it’s possible if you (an another developer) want to customize icons. Example:

function Welcome(props) {
  return <img src={props.icon}>;
}

const root = ReactDOM.createRoot(document.getElementById('root'));
const element = <Welcome icon={new URL("my-library-icons/welcome.svg", import.meta.url)} />;
root.render(element);

Also developer can:

  • optimize svg
  • allow to setup any public path (it will be solved on the bundle side)
  • use it in browsers without bundlers
  • split code as wants
0reactions
xleepycommented, Nov 29, 2022

Thanks for advice! Wish you a nice day!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'bind' of undefined · Issue #296
As i can see chunks are being created for all dynamic imported components so i think we can do code splitting for library...
Read more >
Webpack Import Code Splitting rendering <undefined>
one thing that I have noticed is, no matter what path I give for the component to import, it always imports the chunk....
Read more >
Code-splitting for libraries—bundling for npm with Rollup 1.0
Imagine one module imports the upper function from "fancy-case" while another imports it from "fancy-case/src/upper" .
Read more >
Code Splitting - webpack
The reason we need default is that since webpack 4, when importing a CommonJS module, the import will no longer resolve to the...
Read more >
Lazy loading React components - LogRocket Blog
One approach to code-splitting React components is called route-based code-splitting, which entails applying dynamic import() to lazy load route ...
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