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 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
22 changes: 22 additions & 0 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,28 @@ 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) {
Log.error(
`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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>another app</p>
}
3 changes: 3 additions & 0 deletions test/integration/conflicting-app-page-error/app/hello/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>hello app</p>
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
}
3 changes: 3 additions & 0 deletions test/integration/conflicting-app-page-error/pages/another.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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')
})
})