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.

webpackIgnore prevents polyfilling of dynamic import

See original GitHub issue

Bug report

What is the current behavior?

import( /* webpackIgnore: true */ 'https://external.site/script.js')

should not be interpreted by webpack (which works), but it also does not get transpiled correctly using babel-loader.

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

https://github.com/beckerei/webpack-babel-dynamic-import

There is noch much needed besides webpack, babel-loader and a correct browserlist (so that import should get polyfilled)

It seems that the line containing webpackIgnore is not run through the loaders as well.

It’s kind of hard to find out what exactly webpackIgnore does, it is only ever found in context with import. What does it actually do?

You can find the output from webpack under https://github.com/beckerei/webpack-babel-dynamic-import/blob/master/dist/main.js it still contains import()

What is the expected behavior?

See how the code should be transformed in here https://babeljs.io/repl#?browsers=> 2%25&build=&builtIns=false&spec=false&loose=false&code_lz=FASwtgDg9gTgLgCgAQHoBUSDuBTARhAQwGMBrASQHMA7WbALiThgFdsk0UkByACzjggBnOihTYAHnGwwqBADYA6QSCkpBRGCAhwFAK0FcAlAG5gQA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Cenv&prettier=false&targets=&version=7.8.4&externalPlugins=

Babels preset-env can polyfill import now by default, but adding the import polfyfill plugin does not change the webpack output.

Other relevant information: webpack version: 4.41.6 Node.js version: 13.8.0 Operating System: OSX Additional tools: babel-loader@8.0.6, @babel/preset-env@7.8.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
beckereicommented, Mar 12, 2020

I’ll close this now. Seems only fair as it’s not an webpack issue, it should not count towards the open issue count 👍

1reaction
beckereicommented, Mar 11, 2020

I’m not sure you can import react components with the method I described above. We don’t import a component just a 3rd party script, which has nothing to do with react.

You might be interested in webpacks module federation plugin, read about it https://itnext.io/webpack-5-module-federation-a-game-changer-to-javascript-architecture-bcdd30e02669

As I’m unfamiliar with how exactly systemjs works you might want to give this a try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module Methods - webpack
webpackIgnore : Disables dynamic import parsing when set to true . ... remember to shim Promise using a polyfill such as es6-promise or...
Read more >
Lazy loading polyfills with WebPack and dynamic imports
Lazy loading polyfills. Assuming that your app is already using Webpack and Babel, the first thing you need to do is enable support...
Read more >
Webpack and Dynamic Imports: Doing it Right - Medium
The problem is if you want to dynamically load a file, in this case, an image, Webpack by default generate a chunk for...
Read more >
dynamic import can only be supported when transforming es ...
Dynamic import can only be supported when transforming ES modules to AMD, CommonJS or SystemJS. Only the parser plugin will be enabled.
Read more >
Dynamic loading of external modules in webpack fails
import (/*webpackIgnore: true*/ 'path/to/module.js');. This will both prevent Webpack from attempting to find and bundle the dynamically ...
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