Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - Puppeteer library error: "Cannot find name 'Element'"

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):

enter image description here

error TS2304: Build:Cannot find name 'Element'

How can I resolve this please?

like image 396
aBlaze Avatar asked Sep 18 '19 19:09

aBlaze


People also ask

How to fix the ‘cannot find name’ error in typescript?

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?

How to use puppeteer 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.

How to fix “cannot find name” errors in React components with typescript?

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.

Does puppetteer have a GUI on Chromium?

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.


Video Answer


1 Answers

Adding dom to my tsconfig.json's array of libraries fixed the issue by compiling in the DOM library:

{
    "compilerOptions": {
        "lib": [
            "es2018",
            "dom"
        ]
    }
}
like image 94
aBlaze Avatar answered Sep 22 '22 19:09

aBlaze