Puppeteer types node_modules/puppeteer/lib/types"' has no exported member 'Cookie'

Viewed 555

I have got a problem with puppeteer types, I'm trying to import Cookie type, but it doesn't work on version newer than 6.0.0.

import { Cookie } from 'puppeteer';

and the error

/node_modules/puppeteer/lib/types"' has no exported member 'Cookie'.
2 Answers

if you are still plagued with this in a COVID-endemic world,

You can define your own type using a typings file and then importing it through your tsconfig.json. Of course, there's no need (in most cases) to create your own type, when you can refer to the @types/puppeteer package and pull out the type you need (but that the latest puppeteer version doesn't include). I will allow you to find the mess that is puppeteer typings on your own.

So, say if I ran into a ... has no exported member HttpMethod error, I would create a typings file, (e.g. httpMethod.type.ts) with the following, taken from @types/puppeteer:

export type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' | 'OPTIONS';

Make sure the new typings file is in a folder lower than your tsconfig.json so it can find it.

Then, replace the erroneous import line, e.g.: import { HttpMethod } from 'puppeteer';

to import { HttpMethod } from '../httpMethod.type';

Info from puppeteer documentation, problem solved

We have recently completed a migration to move the Puppeteer source code from JavaScript to TypeScript and as of version 7.0.1 we ship our own built-in type definitions.
Related