0
$ 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.

2 Answers 2

1

this is all you need to do :')

import { http } from "http";
Sign up to request clarification or add additional context in comments.

4 Comments

Tried tsc main.ts and got the same error...
did you installed that first or not?
Install node? I did, isn't http included in nodejs?
Ah... I see now, thanks for the point. I didn't install @types/node.
1

tsc --init

To initialize the Typescript configuration file. The error disappeared for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.