Unverified Commit 23f32465 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

types: mark ImageResponse from next/server deprecated (#57372)

* Should show `ImageResponse` is deprecated if you still import from `"next/server"`

<img width="708" alt="image" src="https://github.com/vercel/next.js/assets/4800338/38f9b9db-2cfb-48ec-99cc-08e7d1477155">


* If you build it will fail to compile, this might not be super ideal but at least it's not working. For pure js it will throw errors.

```ts
./app/icon.tsx:7:10
Type error: Only a void function can be called with the 'new' keyword.

   5 |
   6 | export default function icon() {
>  7 |   return new ImageResponse(
     |          ^
   8 |     (
   9 |       <div
  10 |         style={{
 ELIFECYCLE  Command failed with exit code 1.
 ```
parent 72742966
...@@ -24,6 +24,30 @@ Replacing `<transform>` and `<path>` with appropriate values. ...@@ -24,6 +24,30 @@ Replacing `<transform>` and `<path>` with appropriate values.
## Next.js Codemods ## Next.js Codemods
### 14.0
#### Migrate `ImageResponse` imports
#### `next-og-import`
```bash filename="Terminal"
npx @next/codemod@latest next-og-import.
```
This codemo migrates the import path of `ImageResponse` from `'next/server'` to `'next/og'`
For example:
```js
import { ImageResponse } from 'next/server'
```
Transform into:
```js
import { ImageResponse } from 'next/og'
```
### 13.2 ### 13.2
#### Use Built-in Font #### Use Built-in Font
......
export function ImageResponse() { /**
* @deprecated ImageResponse moved from "next/server" to "next/og" since Next.js 14, please import from "next/og" instead.
* Migration with codemods: https://nextjs.org/docs/app/building-your-application/upgrading/codemods#next-og-import
*/
export function ImageResponse(): never {
throw new Error( throw new Error(
'ImageResponse moved from "next/server" to "next/og" since Next.js 14, please import from "next/og" instead' 'ImageResponse moved from "next/server" to "next/og" since Next.js 14, please import from "next/og" instead'
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment