Home > Mobile >  Node http module is not found when using from typescript
Node http module is not found when using from typescript

Time:11-18

$ node -v
v16.13.0

I'm very new to TS/JS and try to understand how to import modules provided by node js with typescript. Following this How to use Node http module in TypeScript QA I tried it myself and wrote the following simple typescript file:

import * as http from "http"

When running tsc main.ts I got the following error:

main.ts:1:23 - error TS2307: Cannot find module 'http' or its 
corresponding type declarations.

Maybe some more options are required to the tsc? I tried to add tsc --module commonjs main.ts but got the same error.

I thought all node js modules are visible for typescript by default.

CodePudding user response:

this is all you need to do :')

import { http } from "http";
  • Related