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)
This commit is contained in:
Hannes Bornö 2023-02-03 00:37:05 +01:00 committed by GitHub
parent dff39acc30
commit 06b6aa2fa4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View file

@ -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.

View file

@ -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 <Component />
}
`
)
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()
})
}
)