2
votes

In typescript, I get build error saying 'Build:'Promise' only refers to a type, but is being used as a value here.'.

My project target is 'ES5'. From this thread, I can resolve the issue by changing it to ES6. Is there a way to resolve the issue without changing my target?

typescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here

Thank you.

2
it would help if you could post a code example that fails.toskv

2 Answers

9
votes

To solve this without changing lib you have to add @types/node to dependencies or devDependencies this will resolve not only Promise but all node types.

npm i @types/node

Here is my lib:

"target": "es5",
"lib": [
  "dom",
  "es5",
  "dom.iterable",
  "scripthost"
]
4
votes

If you are sure that the environment you are going to run it supports promise, you can target ES5, but add the lib compiler option:

"compilerOptions": {
    // ...
    "target": "es5",
    "lib": [
        "es2015.promise" // Or "es2015" or "es6" should work as well
    ]
}