ulixee / hero

The web browser built for scraping
MIT License
649 stars 32 forks source link

Typescript fails compiling with lib `ESNext` when importing @ulixee/hero-playground #181

Closed IonelLupu closed 1 year ago

IonelLupu commented 1 year ago

Hello everyone. I discovered a very very strange issue. It seems Hero breaks the typescript compiler. For example, having this project setup, makes typescript throw an error:

// tsconfig.json
{
  "compilerOptions": {
    "target": "es2020",
    "lib": ["ESNext"],
    "module": "commonjs",
    "strict": true,
    "skipLibCheck": true 
  }
}
// index.ts
import "@ulixee/hero-playground";
"test".replaceAll("t", '')

Compiling this will result in this error: "Property 'replaceAll' does not exist on type"

But (and here is the weird part), if I comment the "import", the typescript compiler doesn't complain anymore:

// index.ts
//import "@ulixee/hero-playground";
"test".replaceAll("t", '')

compiles with no errors

Does anyone have any idea why is this happening?

To note that replaceAll is a ES2021 feature. It seems @ulixee/hero-playground somehow removes this method from the String object. Is Hero updating the prototype of the String object?

blakebyrnes commented 1 year ago

Hero doesn't manipulate any of the Javascript objects like String. I think this is just typescript deciding to downgrade the code compatibility standard. As to why... I don't have any idea. I'm not even sure we're publishing any typescript related files to npm besides the declaration files. Can you double check that your @ulixee /* npm modules don't include any tsconfig files? I'm fairly certain we're not publishing those, but worth checking

blakebyrnes commented 1 year ago

@IonelLupu Any update here?

IonelLupu commented 1 year ago

hey @blakebyrnes

I check my node_modules and I found these tsconfig.json files:

blakebyrnes commented 1 year ago

Does it fix your issue to remove those files?

IonelLupu commented 1 year ago

Unfortunately, no.

I also tested by importing different modules from @ulixee and it seems that only a few of the contain the problem:

Problem (@ulixee/hero-core for example): image

Not a problem (@ulixee/commons is OK): image

havardox commented 1 month ago

Can someone here post a working TypeScript project using this package? I can't for the life of me get the imports to work

blakebyrnes commented 1 month ago

Can someone here post a working TypeScript project using this package? I can't for the life of me get the imports to work

Can you start a new discussion or issue with your code and the error you're seeing? I don't think many people have reported issues except that they had to set skipLibCheck to true