9
votes

Typescript error error TS2705: 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.

I am getting this error when I am trying to compile any function with async await in it. My tsconfig.json file is this

{
  "compilerOptions": {
    "module": "commonjs",
    "lib": [ "es2015" ],
    "module":"commonjs",
    "target": "es6",
    "moduleResolution" : "node",
    "rootDir": "src/",
    "sourceMap": true
  },
  "includes" : [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

Please help

1
I have tried other methods in git and stack. I have version 8 node and version 3 typescript. - gd vigneshwar
Typescript version 3 is still in development, are you sure you have 3.0 ? Also the tsconfig.json is not valid, it has two module entries - Titian Cernicova-Dragomir
I deleted one of them - gd vigneshwar
Sorry I have 2.9.2 typescript. Sorry - gd vigneshwar
BTW thanks for your replies - gd vigneshwar

1 Answers

9
votes

As se discussed in the comment, you are running the compiler in the command line by specifying the files :

tsc filename.ts

This actually means the compiler will not take into account your tsconfig.json file, it will expect that you specify the all the settings at the command line.

If you want to use a project configuration file (aka tsocnfig.json) you must either specify it explicitly using the -p option. See here for compiler options.

tsc -p tsconfig.json

Or if you run the compiler directly in the project dir where the tsconfig.json is located you can just run the compiler without any options and it will pick the project file named tsconfig.json in the current directory

tsc