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

Add conflicting app and page error #41099

Merged
merged 4 commits into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/next/build/index.ts
Expand Up @@ -551,6 +551,29 @@ export default async function build(
: undefined,
}

if (pageKeys.app) {
const conflictingAppPagePaths = []

for (const appPath of pageKeys.app) {
if (pageKeys.pages.includes(appPath)) {
conflictingAppPagePaths.push(`pages${appPath} - app${appPath}`)
}
}
const numConflicting = conflictingAppPagePaths.length

if (numConflicting > 0) {
console.error(
chalk.red('Error: ') +
ijjk marked this conversation as resolved.
Show resolved Hide resolved
`Conflicting app and page file${
numConflicting === 1 ? ' was' : 's were'
} found, please remove the conflicting files to continue. \n${conflictingAppPagePaths.join(
'\n'
)}\n`
)
process.exit(1)
}
}

const conflictingPublicFiles: string[] = []
const hasPages404 = mappedPages['/404']?.startsWith(PAGES_DIR_ALIAS)
const hasCustomErrorPage =
Expand Down
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>another app</p>
}
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>hello app</p>
}
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>another app</p>
}
5 changes: 5 additions & 0 deletions test/integration/conflicting-app-page-error/next.config.js
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
}
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>another page</p>
}
3 changes: 3 additions & 0 deletions test/integration/conflicting-app-page-error/pages/hello.js
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>hello page</p>
}
20 changes: 20 additions & 0 deletions test/integration/conflicting-app-page-error/test/index.test.js
@@ -0,0 +1,20 @@
/* eslint-env jest */

import path from 'path'
import { nextBuild } from 'next-test-utils'

const appDir = path.join(__dirname, '..')

describe('conflict between app file and page file', () => {
it('errors during build', async () => {
const conflicts = ['/hello', '/another']
const results = await nextBuild(appDir, [], { stdout: true, stderr: true })
const output = results.stdout + results.stderr
expect(output).toMatch(/Conflicting app and page files were found/)

for (const conflict of conflicts) {
expect(output).toContain(conflict)
}
expect(output).not.toContain('/non-conflict')
})
})