【问题标题】:Next.js - Type error: Cannot find name 'StaticImageData'Next.js - 类型错误:找不到名称“StaticImageData”
【发布时间】:2021-12-11 18:23:15
【问题描述】:

我正在尝试将我的代码推送到 Vercel,但在检查类型的有效性时,它在构建步骤中失败。

这是收到的完整错误:

info  - Checking validity of types...
Failed to compile.
./node_modules/next/dist/client/image.d.ts:19:14
Type error: Cannot find name 'StaticImageData'.

我尝试将 Next.js 版本回滚到 11,但没有成功。

编辑:

我发现了这个类似的 Github 问题,但似乎没有太大帮助。

https://github.com/vercel/next.js/issues/29788

【问题讨论】:

    标签: next.js vercel nextjs-image


    【解决方案1】:

    您可以临时创建一个全局类型,直到问题得到解决,如下所示:

    global-types.d.ts

    export {};
    declare global {
      type StaticImageData = {
        src: string
        height: number
        width: number
        blurDataURL?: string
      };
    }
    

    然后将其作为tsconfig.json 文件中的第一项引用:

    "include": ["./global-types.d.ts","next-env.d.ts", "**/*.ts", "**/*.tsx"]
    

    一旦他们解决了问题,请删除参考。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      相关资源
      最近更新 更多