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 IE10 (preset-env core-js@3)

See original GitHub issue

Bug Report

Current Behavior Dynamic imports are not working in IE10. The following error is shown in the console: “Unhandled promise rejectionTypeError: Target is not iterable”. @babel/preset-env is used with core-js@3. .browserslistrc contains ie <= 10.

Input Code https://github.com/jorenvanhee/dynamic-imports-with-preset-env-test

Run npm i && npm run build and visit /index.html in IE10.

import('./answer').then((module) => {
  console.log(module.default);
});

Expected behavior/code 42 should be logged in the console.

Babel Configuration (.babelrc, package.json, cli command)

https://github.com/jorenvanhee/dynamic-imports-with-preset-env-test

Environment

  • Babel version(s): 7.4.3
  • Node/npm version: Node 10.15.1/npm 6.5
  • How you are using Babel: loader

Additional context/Screenshots

Screenshot 2019-04-16 at 17 08 48

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:12
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

17reactions
chenjiahancommented, Jan 8, 2020

Wrote a small plugin to add array.iterator polyfill automatically:

Repo: babel-plugin-dynamic-import-polyfill.

Example

In

import('./foo');

Out

import "core-js/modules/es.object.to-string";
import "core-js/modules/es.promise";
import "core-js/modules/es.array.iterator"; // <- Added by plugin

import('./foo');

Installation

npm install --save-dev babel-plugin-dynamic-import-polyfill

Usage

.babelrc

{
  "plugins": ["babel-plugin-dynamic-import-polyfill"]
}
12reactions
sarodcommented, Apr 18, 2019

@jorenvanhee adding an entry with ‘core-js/modules/es.array.iterator’ in your webpack config should workaround the issue:

entry: [
        'core-js/modules/es.array.iterator',        
        path.join(__dirname, 'src', 'index.js')
    ],
Read more comments on GitHub >

github_iconTop Results From Across the Web

Target browser option in useBuiltIns/babel polyfill
I want to use 'useBuiltIns' option to load polyfills only for IE11 browser. [ '@babel/preset-env', { useBuiltIns: 'entry', debug: ...
Read more >
@babel/plugin-proposal-dynamic-import - Package Manager
Fast, reliable, and secure dependency management.
Read more >
babel/plugin-syntax-dynamic-import
Working with Webpack and @babel/preset-env. Currently, @babel/preset-env is unaware that using import() with Webpack relies on Promise internally.
Read more >
Browser Compatibility of JavaScript modules: dynamic import()
JavaScript modules: dynamic import() shows a browser compatibility score of 88. This is a collective score out of 100 to represent overall ...
Read more >
@babel/plugin-syntax-dynamic-import: Versions | Openbase
7.7.4 · babel-runtime-corejs2 , babel-runtime-corejs3 , babel-runtime · babel-preset-env · babel-parser · babel-preset-env-standalone · babel-plugin-transform- ...
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