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.

Dynamic imports generates wrong Chunks with folder structure `Comment/index.js` and `import './Comment'`

See original GitHub issue

Do you want to request a feature or report a bug? Bug

What is the current behavior?

When using

import(/* webpackChunkName: 'asyncComponents/[request]' */ `./asyncComponents/${name}`)

with this folder structure:

.
└── asyncComponents
    └── Comment
        ├── index.js
        └── styles.css

You would expect the imported chunk name to be asyncComponents/Comment-index or ideally simply asyncComponents/Comment. Instead it’s asyncComponents/Post-.

styles.css for example gets a chunk named: asyncComponents/Page-styles

If the current behavior is a bug, please provide the steps to reproduce.

Use

import(/* webpackChunkName: 'asyncComponents/[request]' */ `./asyncComponents/${name}`)

with the above folder structure and check out the chunk names

What is the expected behavior? Generate same chunk names (Button) as with static compiling

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System. node 8.2.1 webpack 3.5.4 macOS 10.12.6

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
sokracommented, Aug 28, 2017

Thanks for your report. It would be great if you reduce your issue to a small reproducible example. Best put this example into a github repository together with instructions how to get to the problem.

2reactions
ermikcommented, Sep 6, 2018

There are some new issues with this. I had react-universal-component + webpack-flush-chunks + babel-plugin-universal-import working fine until webpack started spitting out chunks with slashes in the file names for where the path went, while the universal component expects hyphens.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Imports: Am I missing something? - Stack Overflow
@Ernesto's answer offers one way of code splitting by using react-loadable with the babel-dynamic-import plugin, however, if your Webpack ...
Read more >
import() - JavaScript - MDN Web Docs - Mozilla
The import() syntax, commonly called dynamic import, is a function-like expression that allows loading an ECMAScript module asynchronously ...
Read more >
Demistifying webpack's 'import' function: using dynamic ...
webpack will generate a chunk for each file in the animals directory. This is the lazy option's behaviour. What happens in this example...
Read more >
Dynamic imports - The Modern JavaScript Tutorial
First, we can't dynamically generate any parameters of import . The module path must be a primitive string, can't be a function call....
Read more >
babel-plugin-path-chunk-name - npm
By default, webpack will generate dynamic chunks named with numeric value, say 0.js . · It's troublesome to add magic comments: webpackChunkName ...
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