vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.87k stars 26.97k forks source link

pages folder in src not ignored when app folder exists in root #58728

Open atstoyanov opened 11 months ago

atstoyanov commented 11 months ago

Link to the code that reproduces this issue

https://github.com/atstoyanov/nextjs-build-fail

To Reproduce

  1. Clone the repository
  2. Execute npm i and npm run build

Current vs. Expected behavior

Current: Running npm run build results into:

Build optimization failed: found page without a React Component as default export in 
pages/TestPage

Expect: Components in src/pages to not to be counted as pages when the /app folder exists.

According to the documentation: https://nextjs.org/docs/app/building-your-application/configuring/src-directory

src/app or src/pages will be ignored if app or pages are present in the root directory.

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.0.4-canary.6
  eslint-config-next: 14.0.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.6
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

App Router

Additional context

No response

atstoyanov commented 11 months ago

Adding an empty pages folder in the root prevents .nextjs from trying to generate static pages from src/pages. It wasn't obvious to me.

jinyoung4478 commented 6 months ago

Adding an empty pages folder to the root directory also causes issues with the middleware of Next.js not functioning properly.

creator-woow commented 5 months ago

@atstoyanov Do you solve the problem or just create empty pages folder at the root of your project?

atstoyanov commented 5 months ago

@creator-woow I've just created an empty pages folder in the project root with .gitkeep file inside so it is cloned on other locations. @jinyoung4478 I'm going to implement a middleware very soon and will have more information. In general my plan is to restructure the whole project and get rid of the src folder.