File tree Expand file tree Collapse file tree 12 files changed +69
-14
lines changed Expand file tree Collapse file tree 12 files changed +69
-14
lines changed Original file line number Diff line number Diff line change 1
1
const { platform } = require ( 'process' )
2
2
const fsPromises = require ( 'fs/promises' )
3
+ const { satisfies } = require ( 'semver' )
3
4
4
5
// Next.js uses `fs.promises.copyFile` to copy files from `.next`to the `.next/standalone` directory
5
6
// It tries copying the same file twice in parallel. Unix is fine with that, but Windows fails
@@ -28,4 +29,27 @@ module.exports = {
28
29
ignoreDuringBuilds : true ,
29
30
} ,
30
31
outputFileTracingRoot : __dirname ,
32
+ // there is no single way to use `next/og` or `@vercel/og` depending on Next.js version
33
+ // - next@<14 doesn't have 'next/og' export
34
+ // - next turbopack builds doesn't work with `@vercel/og`
35
+ // so this adds `next-og-alias` alias depending on next version for both webpack and turbopack
36
+ // so we can test this in all the versions
37
+ webpack : ( config ) => {
38
+ const hasNextOg = ! satisfies ( require ( 'next/package.json' ) . version , '<14.0.0' , {
39
+ includePrerelease : true ,
40
+ } )
41
+
42
+ if ( ! hasNextOg ) {
43
+ config . resolve . alias [ 'next-og-alias$' ] = '@vercel/og'
44
+ } else {
45
+ config . resolve . alias [ 'next-og-alias$' ] = 'next/og'
46
+ }
47
+
48
+ return config
49
+ } ,
50
+ turbopack : {
51
+ resolveAlias : {
52
+ 'next-og-alias' : 'next/og' ,
53
+ } ,
54
+ } ,
31
55
}
Original file line number Diff line number Diff line change 11
11
"@vercel/og" : " latest" ,
12
12
"next" : " latest" ,
13
13
"react" : " 18.2.0" ,
14
- "react-dom" : " 18.2.0"
14
+ "react-dom" : " 18.2.0" ,
15
+ "semver" : " ^7.7.2"
15
16
}
16
17
}
Original file line number Diff line number Diff line change 1
- import { ImageResponse } from '@vercel/og'
1
+ // see next.config for details about 'next-og-alias'
2
+ import { ImageResponse } from 'next-og-alias'
2
3
3
4
export async function GET ( ) {
4
5
return new ImageResponse ( < div > hi</ div > , {
Original file line number Diff line number Diff line change 1
- import { ImageResponse } from '@vercel/og'
1
+ // see next.config for details about 'next-og-alias'
2
+ import { ImageResponse } from 'next-og-alias'
2
3
3
4
export async function GET ( ) {
4
5
return new ImageResponse ( < div > hi</ div > , {
Original file line number Diff line number Diff line change 1
- // /pages/api/og.jsx
2
- import { ImageResponse } from '@vercel/og '
1
+ // see next.config for details about 'next-og-alias'
2
+ import { ImageResponse } from 'next-og-alias '
3
3
4
4
export default function ( ) {
5
5
return new ImageResponse (
Original file line number Diff line number Diff line change 1
- // /pages/api/og.jsx
2
- import { ImageResponse } from '@vercel/og '
1
+ // see next.config for details about 'next-og-alias'
2
+ import { ImageResponse } from 'next-og-alias '
3
3
4
4
export const config = {
5
5
runtime : 'edge' ,
Original file line number Diff line number Diff line change 1
- import { ImageResponse } from '@vercel/og'
1
+ // see next.config for details about 'next-og-alias'
2
+ import { ImageResponse } from 'next-og-alias'
2
3
3
4
export async function GET ( ) {
4
5
return new ImageResponse ( < div > hi</ div > , {
Original file line number Diff line number Diff line change 1
- import { ImageResponse } from '@vercel/og'
1
+ // see next.config for details about 'next-og-alias'
2
+ import { ImageResponse } from 'next-og-alias'
2
3
3
4
export async function GET ( ) {
4
5
return new ImageResponse ( < div > hi</ div > , {
Original file line number Diff line number Diff line change 1
1
const { platform } = require ( 'process' )
2
2
const fsPromises = require ( 'fs/promises' )
3
+ const { satisfies } = require ( 'semver' )
3
4
4
5
// Next.js uses `fs.promises.copyFile` to copy files from `.next`to the `.next/standalone` directory
5
6
// It tries copying the same file twice in parallel. Unix is fine with that, but Windows fails
@@ -28,4 +29,28 @@ module.exports = {
28
29
ignoreDuringBuilds : true ,
29
30
} ,
30
31
outputFileTracingRoot : __dirname ,
32
+ outputFileTracingRoot : __dirname ,
33
+ // there is no single way to use `next/og` or `@vercel/og` depending on Next.js version
34
+ // - next@<14 doesn't have 'next/og' export
35
+ // - next turbopack builds doesn't work with `@vercel/og`
36
+ // so this adds `next-og-alias` alias depending on next version for both webpack and turbopack
37
+ // so we can test this in all the versions
38
+ webpack : ( config ) => {
39
+ const hasNextOg = ! satisfies ( require ( 'next/package.json' ) . version , '<14.0.0' , {
40
+ includePrerelease : true ,
41
+ } )
42
+
43
+ if ( ! hasNextOg ) {
44
+ config . resolve . alias [ 'next-og-alias$' ] = '@vercel/og'
45
+ } else {
46
+ config . resolve . alias [ 'next-og-alias$' ] = 'next/og'
47
+ }
48
+
49
+ return config
50
+ } ,
51
+ turbopack : {
52
+ resolveAlias : {
53
+ 'next-og-alias' : 'next/og' ,
54
+ } ,
55
+ } ,
31
56
}
Original file line number Diff line number Diff line change 11
11
"@vercel/og" : " latest" ,
12
12
"next" : " latest" ,
13
13
"react" : " 18.2.0" ,
14
- "react-dom" : " 18.2.0"
14
+ "react-dom" : " 18.2.0" ,
15
+ "semver" : " ^7.7.2"
15
16
}
16
17
}
You can’t perform that action at this time.
0 commit comments