Promise only refers to a type error: how to solve it?

Gabriel Guerra
2 min readJul 18, 2021

When transpiling TypeScript you could get the error:

error TS2585: Promise only refers to a type, but is being used as a var here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.

It's an interesting scenario, since the code below shouldn't be throwing errors.

It's a commom TypeScript error and in most of the cases it should be solved in two ways:

  1. Check if your target is es2015 or later, as suggested in the error message;
  2. Install @types/node from npm;
npm instal@types/node

After that, magically the error has disapeared!

That's all folks! Happy coding!

--

--