HiveBrain v1.2.0
Get Started
← Back to all entries
snippettypescriptCritical

TypeScript compiler says “An async function or method in ES5/ES3 requires the 'Promise' constructor”; how do I solve this?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
typescriptes5constructorhowfunctiones3themethodrequirespromise

Problem

Hello I'm using async/await in my TypeScript project, But I get this log:

[ts] An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option.

How can I solve that?

Solution

As the error message says, add lib: es2015 to your tsconfig.json

// tsconfig.json
{
  "compilerOptions": {
    "lib": [ "es2015" ]
  }
}


UPDATE: if this doesn't work for you, try this:

JetBrains IDE such as WebStorm, use its own implementation by default. Make sure you configure it to use TypeScript language service instead.

For Visual Studio, the project files and tsconfig.json are mutually exclusive. You will need to configure your project directly.

https://github.com/Microsoft/TypeScript/issues/3983#issuecomment-123861491

Code Snippets

// tsconfig.json
{
  "compilerOptions": {
    "lib": [ "es2015" ]
  }
}

Context

Stack Overflow Q#43555378, score: 236

Revisions (0)

No revisions yet.