Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module '"http"' has no default export. While using typescript And Node

    import http from 'http';
    http.createServer((req, res) => {
      res.end('Hello World');
    }).listen(3000, () => console.log('Port is running on 3000'));

I am using @types/node but it shows an error HTTP module does not have default export.

like image 345
Ashutosh sarangi Avatar asked May 10 '26 06:05

Ashutosh sarangi


2 Answers

You probably need to import the module like this

import * as http from 'http'

like image 194
omeanwell Avatar answered May 11 '26 21:05

omeanwell


{
    "compilerOptions": {
        "esModuleInterop": true
    },

}

Just add esModuleInterop at your tsconfig.json file

like image 21
Tanjin Alam Avatar answered May 11 '26 19:05

Tanjin Alam