【问题标题】:Puppeteer types node_modules/puppeteer/lib/types"' has no exported member 'Cookie'Puppeteer 类型 node_modules/puppeteer/lib/types"' 没有导出成员 'Cookie'
【发布时间】:2021-05-22 07:23:59
【问题描述】:

我遇到了 puppeteer 类型的问题,我正在尝试导入 Cookie 类型,但它不适用于高于 6.0.0 的版本。

import { Cookie } from 'puppeteer';

还有错误

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

【问题讨论】:

    标签: node.js typescript express types puppeteer


    【解决方案1】:

    如果您在 COVID 流行的世界中仍然为此困扰,

    您可以使用类型文件定义自己的类型,然后通过您的tsconfig.json 将其导入。当然,(在大多数情况下)不需要创建自己的类型,您可以参考 @types/puppeteer 包并提取您需要的类型(但最新的 puppeteer 版本不包括)。我会让你自己找到傀儡打字的烂摊子。

    所以,假设我遇到... has no exported member HttpMethod 错误,我会创建一个类型文件,(例如httpMethod.type.ts),其中包含以下内容,取自@types/puppeteer:

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

    确保新的类型文件位于低于您的tsconfig.json 的文件夹中,以便它可以找到它。

    然后,替换错误的导入行,例如: import { HttpMethod } from 'puppeteer';

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

    【讨论】:

      【解决方案2】:

      来自 puppeteer 文档的信息,问题已解决

      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.
      

      【讨论】:

        猜你喜欢
        • 2021-03-10
        • 2021-05-26
        • 2019-05-10
        • 2019-01-24
        • 1970-01-01
        • 2017-12-29
        • 2018-11-07
        • 2018-10-20
        • 2019-01-17
        相关资源
        最近更新 更多