Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support next/og usage in ESM nextjs app #60818

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/build/handle-externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export function makeExternalHandler({

// ESM externals can only be imported (and not required).
// Make an exception in loose mode.
if (!isEsmRequested && isEsm && !looseEsmExternals) {
if (!isEsmRequested && isEsm && !looseEsmExternals && !isLocal) {
throw new Error(
`ESM packages (${request}) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals`
)
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/app-dir/app-esm-js/app/opengraph-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ImageResponse } from 'next/og'

export default function OpenGraphImage() {
return new ImageResponse(
(
<div
style={{
width: 1200,
height: 630,
backgroundColor: '#000',
color: '#fff',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column',
fontFamily: 'sans-serif',
}}
>
OG
</div>
)
)
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/app-esm-js/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ createNextDescribe(
)
expect(await $('.root').text()).toContain('pages')
})

it('should support next/og image', async () => {
const res = await next.fetch('/opengraph-image')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toBe('image/png')
})
}
)