SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
358 stars 114 forks source link

Typescript error on page #105

Closed itsikbelson-spotlight closed 1 year ago

itsikbelson-spotlight commented 1 year ago

I have the following dependencies in my package.json

      "puppeteer": "20.3.0",
      "puppeteer-stream": "3.0.4",
      "@types/puppeteer": "7.0.4",

I have the following code:

import { getStream, launch } from 'puppeteer-stream';
import { Page } from 'puppeteer';
...
const browser = await launch(config);
console.log('Opening new page');
const page: Page = await browser.newPage();

I get an error in the IDE for page:

TS2322: Type 'import("/Users/itsikbelson/dev/session-recorder/node_modules/puppeteer-stream/node_modules/puppeteer-core/lib/types").Page' is not assignable to type 'import("/Users/itsikbelson/dev/session-recorder/node_modules/puppeteer/lib/types").Page'.   Property '#private' in type 'Page' refers to a different member that cannot be accessed from within type 'Page'.

In tsconfig.json I have:

   "compilerOptions": {
      "skipLibCheck": true,
   },

What is the reason for this error?

nivhsay commented 1 year ago

You don't need to add puppeteer explicitly as a dependency. You are probably forcing a version that is different from what puppeteer-stream uses. This will cause your project to have 2 versions of Page: one under the main node_modules, and one under node_modules in puppeteer-stream.

npm/yarn will install puppeteer-core version as required by puppeteer-stream if you omit the explicit dependency.

Then use import { Page } from 'puppeteer-core instead and you will be fine.