【问题标题】:Module '"next"' has no exported member 'NextApiRequest' in version Next.js ^12.1.16模块 '"next"' 在 Next.js ^12.1.16 版本中没有导出成员 'NextApiRequest'
【发布时间】:2022-06-20 23:28:26
【问题描述】:

当尝试为版本 >= 12.1.16 键入 Next.js API 的请求/响应对象时,会出现以下任一错误:

Module '"next"' has no exported member 'NextApiRequest'. 

或

Module '"next"' has no exported member 'NextApiResponse'. 

这在 < 12.1.16 版本中不是问题,但现在是。

如何解决这个问题?

【问题讨论】:

    标签: typescript types next.js


    【解决方案1】:

    要解决此问题,您只需从next/types 模块导入Next.js > 12.1.16 的版本:

    import type { NextApiRequest, NextApiResponse } from "next/types";
    

    Intellisense 可能会帮助您解决这个问题,但如果不能,您可以查看next/types/index.d.ts 文件。只要您使用 TypeScript 初始化项目,Next.js 将提供自己的类型,并且它们都可以在该文件中找到 - 每个类型导入都来自该路径。

    当我提出并回答这个问题时,我在官方文档中找不到任何关于它的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 2017-05-07
      • 2017-08-18
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      相关资源
      最近更新 更多