From 06b6aa2fa44bc9bdd990bdca7fa51e2682756caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Born=C3=B6?= Date: Fri, 3 Feb 2023 00:37:05 +0100 Subject: [PATCH] Error when exporting AMP config in app dir (#45228) Errors in app-render if an exported amp config is found. Fixes NEXT-223 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- packages/next/src/server/app-render.tsx | 6 +++ .../unsupported-app-features.test.ts | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/development/acceptance-app/unsupported-app-features.test.ts diff --git a/packages/next/src/server/app-render.tsx b/packages/next/src/server/app-render.tsx index 6018b71eb2..c30b545195 100644 --- a/packages/next/src/server/app-render.tsx +++ b/packages/next/src/server/app-render.tsx @@ -1373,6 +1373,12 @@ export async function renderToHTMLOrFlight( `The default export of notFound is not a React Component in ${segment}` ) } + + if (layoutOrPageMod?.config?.amp) { + throw new Error( + 'AMP is not supported in the app directory. If you need to use AMP it will continue to be supported in the pages directory.' + ) + } } // Handle dynamic segment params. diff --git a/test/development/acceptance-app/unsupported-app-features.test.ts b/test/development/acceptance-app/unsupported-app-features.test.ts new file mode 100644 index 0000000000..acaec41bb1 --- /dev/null +++ b/test/development/acceptance-app/unsupported-app-features.test.ts @@ -0,0 +1,41 @@ +/* eslint-env jest */ +import { sandbox } from './helpers' +import { createNextDescribe, FileRef } from 'e2e-utils' +import path from 'path' + +createNextDescribe( + 'Error Overlay unsupported app features', + { + files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), + dependencies: { + react: 'latest', + 'react-dom': 'latest', + }, + skipStart: true, + }, + ({ next }) => { + it('should show error exporting AMP config in app dir', async () => { + const { session, cleanup } = await sandbox(next) + + // Add AMP exprot + await session.patch( + 'app/page.js', + ` + export const config = { amp: true } + + import Component from '../index' + export default function Page() { + return + } + ` + ) + + await session.hasRedbox(true) + expect(await session.getRedboxDescription()).toInclude( + 'AMP is not supported in the app directory. If you need to use AMP it will continue to be supported in the pages directory.' + ) + + await cleanup() + }) + } +)