ibrod83 / nodejs-file-downloader

129 stars 23 forks source link

http has no default export member (typescript error 1192) #38

Closed TIRTAGT closed 2 years ago

TIRTAGT commented 2 years ago

It looks like the target was to import "anything" inside "http" module as "http", instead of trying to import default on "http" module.

This screenshot shows the typescript error I receive : image

As I did not want to turn on "skipLibCheck" on TypeScript, I forked the nodejs-file-downloader repository and made the patch. I submit this pull request as it could have resolve any similar issue that I got.

Though as I see the http import are only used for getting the IncomingMessage type, the import can be simplified into :

// File: Downloader.td.ts
// Only import the type that we need
import { IncomingMessage } from 'http';

// and the onResponse@r parameter type can be changed into :
onResponse?(r: IncomingMessage):boolean|void

This typescript issue was produced in my environment:

ibrod83 commented 2 years ago

I have to say that i didn't manage to reproduce the problem, as long as the TS-based program has @types/node installed. I've tried both in a clean TS setup with(tsc --init) and in a NestJs application.

TIRTAGT commented 2 years ago

Hmmm, I do have the node typing installed and it's nearly on the latest version (latest was 17.0.21, while mine was 17.0.19).

But it looks like might be just my environment issue, weirdly doing the patch was the only way for me to resolve the issue and let my project compile.

I tried restarting the ts server, and setting up a new environment together with cloning my project repository and doing npm install, but weirdly nothing work.

Could be my tsconfig.json or package.json was the issue since I didn't check whether the issue persist with a clean project yet, but as it looks like the issue seems to be just my environment issue, I'm closing it.