Beniamino_Baggins Beniamino_Baggins - 1 year ago 387
TypeScript Question

Async functions are only available when targeting ECMAScript 2015 or higher

I want to be able to use the async keyword but I want my typescript to compile into es5 code so that my code can run in the average persons browser. I get this error when I try to use

in visual studio code.

Async functions are only available when targeting ECMAScript 2015 or

I thought that targeting
means that the output javascript from compiling the typescript will be
, and
doesn't work on most browsers yet?

Here is my

"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"lib": ["es2015", "dom"],
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"typeRoots": [
"exclude": [

I was wondering if the
field might make it work because it says
but it doesn't.

I'm also thinking maybe the
shim makes
available but I only include that shim in my
like this:

<script src="node_modules/core-js/client/shim.min.js"></script>

So I don't think it's making
available at compile time. Is there a better way to import core-js?

How do I make
usable but also not have my code be unable to run on most browsers?

Answer Source

ECMAScript6 is supported in most major browsers.



From Safari's website,

ES6 The ECMAScript 2015 standard, also known as ES6, is completely supported, bringing this major JavaScript evolution to Safari on macOS and iOS.

You are going to have to change,

"target": "es5",


"target": "es6",

TypeScript 1.7 async/await support in ES6 targets (Node v4+) TypeScript now supports asynchronous functions for engines that have native support for ES6 generators, e.g. Node v4 and above. Asynchronous functions are prefixed with the async keyword; await suspends the execution until an asynchronous function return promise is fulfilled and unwraps the value from the Promise returned.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download