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 11const { platform } = require ( 'process' )
22const fsPromises = require ( 'fs/promises' )
3+ const { satisfies } = require ( 'semver' )
34
45// Next.js uses `fs.promises.copyFile` to copy files from `.next`to the `.next/standalone` directory
56// It tries copying the same file twice in parallel. Unix is fine with that, but Windows fails
@@ -28,4 +29,27 @@ module.exports = {
2829 ignoreDuringBuilds : true ,
2930 } ,
3031 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+ } ,
3155}
Original file line number Diff line number Diff line change 1111 "@vercel/og" : " latest" ,
1212 "next" : " latest" ,
1313 "react" : " 18.2.0" ,
14- "react-dom" : " 18.2.0"
14+ "react-dom" : " 18.2.0" ,
15+ "semver" : " ^7.7.2"
1516 }
1617}
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'
23
34export async function GET ( ) {
45 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'
23
34export async function GET ( ) {
45 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 '
33
44export default function ( ) {
55 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 '
33
44export const config = {
55 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'
23
34export async function GET ( ) {
45 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'
23
34export async function GET ( ) {
45 return new ImageResponse ( < div > hi</ div > , {
Original file line number Diff line number Diff line change 11const { platform } = require ( 'process' )
22const fsPromises = require ( 'fs/promises' )
3+ const { satisfies } = require ( 'semver' )
34
45// Next.js uses `fs.promises.copyFile` to copy files from `.next`to the `.next/standalone` directory
56// It tries copying the same file twice in parallel. Unix is fine with that, but Windows fails
@@ -28,4 +29,28 @@ module.exports = {
2829 ignoreDuringBuilds : true ,
2930 } ,
3031 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+ } ,
3156}
Original file line number Diff line number Diff line change 1111 "@vercel/og" : " latest" ,
1212 "next" : " latest" ,
1313 "react" : " 18.2.0" ,
14- "react-dom" : " 18.2.0"
14+ "react-dom" : " 18.2.0" ,
15+ "semver" : " ^7.7.2"
1516 }
1617}
You can’t perform that action at this time.
0 commit comments