Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] TypeScript issues with puppeteer v7 ("no exported member" error, etc) #428

Closed
davidbielik opened this issue Feb 13, 2021 · 12 comments
Closed
Labels
issue: bug report A bug has been reported puppeteer-limitation This is a limitation imposed by the original puppeteer upstream-issue The issue is caused by a dependency workaround-available

Comments

@davidbielik
Copy link

Describe the bug
Minimum Reproducible Code

  1. unzip this file
  2. run npm install
  3. run tsc

Expected: typescript compiles
Actual: lots of "namespace has no exported member" errors

This is just from importing the library. When I have actual puppeteer code i get many more errors for lots of other un-exported modules.

node_modules/puppeteer-extra-plugin/dist/index.d.ts:315:39 - error TS2694: Namespace '"/puppeteer-extra-bug/node_modules/puppeteer/lib/types"' has no exported member 'Worker'.

315     onWorkerCreated(worker: Puppeteer.Worker): Promise<void>;
                                          ~~~~~~

node_modules/puppeteer-extra/dist/puppeteer.d.ts:6:10 - error TS2305: Module '"../../puppeteer/lib/types"' has no exported member 'FetcherOptions'.

6 export { FetcherOptions } from 'puppeteer';
           ~~~~~~~~~~~~~~

[10:54:40 AM] Found 2 errors. Watching for file changes.

Code Snippet

import puppeteer from "puppeteer-extra";
import StealthPlugin from "puppeteer-extra-plugin-stealth";
puppeteer.use(StealthPlugin());

Versions

System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 139.73 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.23.1 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.10 - /usr/local/bin/npm
  npmPackages:
    puppeteer: ^7.1.0 => 7.1.0 
    puppeteer-extra: ^3.1.16 => 3.1.16 
    puppeteer-extra-plugin-stealth: ^2.7.4 => 2.7.4 
@davidbielik davidbielik added issue: bug report A bug has been reported needs triage labels Feb 13, 2021
@berstend
Copy link
Owner

berstend commented Feb 13, 2021

@davidbielik puppeteer has broken typings in recent versions, just look at this mess:
https://github.com/puppeteer/puppeteer/releases

Solution: Use puppeteer@5 for now.

Longer answer: It's painful to see that puppeteer broke perfectly fine typings through @types/puppeteer. Due to them shipping their own (somewhat broken) builtin types the dedicated typing package won't be used anymore if present. I'm monitoring the situation but it's really up to the puppeteer project to fix this typing mess.

Even without using -extra you will see TypeScript issues with puppeteer@7

@berstend
Copy link
Owner

I've added a note in the main readme (in the hopes people will see it):

image

@berstend
Copy link
Owner

Just to track some issues regarding the upstream puppeteer typing issues:
puppeteer/puppeteer#6899
puppeteer/puppeteer#6885

@berstend berstend changed the title [Bug] basic typescript integration fails with "no exported member" errors [Bug] TypeScript issues with puppeteer v7 ("no exported member" error, etc) Feb 18, 2021
@1nVitr0
Copy link

1nVitr0 commented Mar 13, 2021

Yeah it's a real tragedy. Of 100 types the @types/puppeteer package originally exported, 51 are no longer available with an additional 23 that no longer match the original types for various reasons. And that's just the top level type exports.

To burn through 3 major versions in a matter of a month is not something you see everyday...

@berstend
Copy link
Owner

Yeah it's a real tragedy. Of 100 types the @types/puppeteer package originally exported, 51 are no longer available with an additional 23 that no longer match the original types for various reasons. And that's just the top level type exports.

To burn through 3 major versions in a matter of a month is not something you see everyday...

100% agree. It's really painful to the point where I halted the #303 release until they sorted this out.

@PurplProto
Copy link

Solution: Use puppeteer@5 for now.

Was this ever confirmed to work? It's still completely broken 😢 I tried v5.0.0 and v5.5.0

@1nVitr0
Copy link

1nVitr0 commented Jun 7, 2021

Was this ever confirmed to work? It's still completely broken I tried v5.0.0 and v5.5.0

I've been working with @5 before puppeteer came and broke their typings and it still works fine. Did you remove the @6+ version of puppeteer from the node_modules folder and include @types/puppeteer as a dev dependency?

@PurplProto
Copy link

PurplProto commented Jun 10, 2021

I've been working with @5 before puppeteer came and broke their typings and it still works fine. Did you remove the @6+ version of puppeteer from the node_modules folder and include @types/puppeteer as a dev dependency?

I realised what the issue was, this package (at least on that version) doesn't appear to have complete coverage of passing through the types provided by @types/puppeteer so, at face value, I just saw redlines in VSCode and instantly came to the conclusion it was broken.

I was wrong, it was just some types that didn't work through the puppeteer-extra package, I just instead cast them as the types I knew they were and things seemed to work again 🙂 I'm not sure if there's a more well-established solution for this, but I haven't bothered to check either, it was just for a quick and dirty script, for now at least 😁

@miramardesign
Copy link

@PairedPrototype can you provide an example? of your fix? Should i import puppeteer extra and cast somehow?
im getting something like: { bindAddress: string; executablePath: string; args: string[]; }' is not assignable to parameter of type 'LaunchOptions

@PurplProto
Copy link

@miramardesign Hey, sorry for the delayed reply.

I've created a working minimal-ish example repo showing how I used the package to achieve my goal. I hope it helps 🙂

@temporaryna
Copy link

still problems with typescript and puppeteer 10.1.0?

@berstend
Copy link
Owner

This should now be fixed through #555:

Successfully published:
 - puppeteer-extra-plugin-adblocker@2.12.0
 - puppeteer-extra-plugin-anonymize-ua@2.3.0
 - puppeteer-extra-plugin-block-resources@2.3.0
 - puppeteer-extra-plugin-click-and-wait@2.3.0
 - puppeteer-extra-plugin-devtools@2.3.0
 - puppeteer-extra-plugin-flash@2.3.0
 - puppeteer-extra-plugin-font-size@2.3.0
 - puppeteer-extra-plugin-recaptcha@3.5.0
 - puppeteer-extra-plugin-repl@2.3.0
 - puppeteer-extra-plugin-stealth@2.8.0
 - puppeteer-extra-plugin-user-data-dir@2.3.0
 - puppeteer-extra-plugin-user-preferences@2.3.0
 - puppeteer-extra-plugin@3.2.0
 - puppeteer-extra@3.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug report A bug has been reported puppeteer-limitation This is a limitation imposed by the original puppeteer upstream-issue The issue is caused by a dependency workaround-available
Projects
None yet
Development

No branches or pull requests

6 participants