Skip to content
Advertisement

Babel with Internet Explorer

Why isn’t this working in IE11 ?

I was under the impression that Babel will automatically convert new-style code to old-style. Is there some configuration setup to be done ?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Babel Test</title>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
document.addEventListener("DOMContentLoaded", () =>
{
    (async () =>
    {
        const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
        const content = await response.json();
        alert(content.title);
    })();    
});
</script>
</head>
<body>
</body>
</html>

Advertisement

Answer

Babel can transform language features from newer versions of JavaScript into equivalents in older versions.

It can’t polyfill APIs which aren’t supported (like fetch). You would need to find an explicit fetch polyfill for that.


Additionally, the browser-side version of Babel will only transform scripts marked as type="text/babel" and (before you edited the question) you didn’t have any of those so your arrow functions, async and await keywords wouldn’t have be transformed.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement