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.

Unable to use import() with magic comments

See original GitHub issue

import(/* webpackChunkName: "plugin" */ './plugin.js') sets chunk [name] the same as [id], so the output filename is 0.0.js (in config: chunkFilename: '[id].[name].js')

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:10
  • Comments:6

github_iconTop GitHub Comments

13reactions
Armourcommented, Aug 20, 2018

Make sure you set:

  • comments: true in .babalrc (this is the default)
  • chunkFilename: '[name].....' in your webpack config

If you are using typescript, also make sure:

  • removeComments: false under compilerOptions in tsconfig.json
  • module: esnext in tsconfig.json

This works for me and here is my commit for adding dynamic import (code split) support to my react-typescript project, hope it helps 😃

0reactions
jose-bernard-receevecommented, Jul 20, 2022

Make sure you set:

  • comments: true in .babalrc (this is the default)
  • chunkFilename: '[name].....' in your webpack config

If you are using typescript, also make sure:

  • removeComments: false under compilerOptions in tsconfig.json
  • module: esnext in tsconfig.json

This works for me and here is my commit for adding dynamic import (code split) support to my react-typescript project, hope it helps 😃

Thank you!! it was the module": "esnext" for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular8.0 dynamic import not support webpack magic ...
1 Answer 1 ... It's working when you build for development mode only. Make sure to set the flag namedChunks in Angular.json to...
Read more >
How to use Webpack's new “magic comment” feature with ...
There is one problem with this. Currently require. resolveWeak can't resolve dynamic imports like import can. I.e. you can't have a string such ......
Read more >
Fixing WebpackChunkName for Dynamic Imports - Time to Hack
If Magic Comments (or Any Comment) are not reaching the webpack, then they are lost in the transpiling process. This means I need...
Read more >
Code Splitting - webpack
It isn't as flexible and can't be used to dynamically split code with the core ... The first and recommended approach is to...
Read more >
How To Fix "Cannot use import statement outside module" in JS
Conclusion. Give these solutions a try and you should no longer have to deal with that error. If not, feel free to leave...
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