3

I am trying to push my code to Vercel, it fails in the build steps when checking the validity of the types.

This is the full error received:

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

I tried rolling back the Next.js version to 11, which didn’t work.

Edit:

I found this similar Github issue however it doesn’t seem to have been much help.

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

1
  • Did you try importing that Type from Next? import { StaticImageData } from "next/image" Commented Aug 16, 2022 at 14:57

2 Answers 2

9

As of February 16th 2022 this has been fixed, now you can just import StaticImageData like so:

import { StaticImageData } from "next/image"
Sign up to request clarification or add additional context in comments.

Comments

4

You can temporarily create a global type until the issue is resolved like so:

global-types.d.ts

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

Then reference it as the first item in your tsconfig.json file:

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

Once they fix the issue, remove the reference.

2 Comments

This did not work for me. Still get the same error as OP.
This worked for me.. but I didn't have to create a separate "global" types declaration file.. I simply put type StaticImageData = { src: string; height: number; width: number; blurDataURL?: string; } in the same TS file with the calling script. Then, I set my interface Props to handle it: src?: string | StaticImageData

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.