I have included puppeteer-core
as a dependency in my TypeScript project, and am using Visual Studio 2019. When I try to build the project, I get this error below (as shown by the red squiggly underline under Element
):
error TS2304: Build:Cannot find name 'Element'
How can I resolve this please?
To fix the "Cannot find name" errors in React components with TypeScript, we should rename any files with the .ts extension to .tsx. ← How to fix the ‘Cannot invoke an expression whose type lacks a call signature’ error in TypeScript? → How to extend an array in TypeScript?
What we need to do to use Puppeteer in TypeScript are 1) Install Puppeteer and Puppeteer type definitin, 2) Include type definition file into tsconfig.json. Type definition file is put in node_modules/@types/puppeteer/index.d.ts. You can use Puppetter without any warning now.
To fix the "Cannot find name" errors in React components with TypeScript, we should rename any files with the .ts extension to .tsx. We need to rename them so that the TypeScript compiler knows that the files can contain JSX code, which it isn’t expecting in .ts files.
Even though Puppetteer does not actually display a GUI, the Chromium instance it uses still requires some of the libraries to draw a GUI and connect to the X11 server, even though that isn’t used in Puppetteer. One of those libraries is libxcb which provides the shared library libX11-xcb.so.1.
Adding dom
to my tsconfig.json
's array of libraries fixed the issue by compiling in the DOM library:
{
"compilerOptions": {
"lib": [
"es2018",
"dom"
]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With