The best solution is to get a copy of Node's type definitions. This will solve all kinds of dependency issues, not only require()
. This was previously done using packages like typings
, but as Mike Chamberlain mentioned, Typings are deprecated. The modern way is doing it like this:
npm install --save-dev @types/node
Not only will it fix the compiler error, it will also add the definitions of the Node API to your IDE.