vercel / next.js

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

Next export with appDir fails #45507

Open kevzettler opened 1 year ago

kevzettler commented 1 year ago

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101
Binaries:
  Node: 18.13.0
  npm: 8.19.3
  Yarn: 3.4.1
  pnpm: N/A
Relevant packages:
  next: 13.1.7-canary.2
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Static HTML Export (next export)

Link to the code that reproduces this issue

https://github.com/kevzettler/bad-nextjs-export-bug

To Reproduce

npm install && next build && next export

Describe the Bug

next export fails with the following

warn  - You have enabled experimental feature (appDir) in next.config.js.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback

info  - using build directory: /Users/kevzettler/code/bad-nextjs-export-bug/.next
info  - Copying "static build" directory
info  - No "exportPathMap" found in "/Users/kevzettler/code/bad-nextjs-export-bug/next.config.js". Generating map from "./pages"
info  - Launching 7 workers
info  - Copying "public" directory
info  - Exporting (2/2)
PageNotFoundError: Cannot find module for page: /about
    at Object.getPagePath (/Users/kevzettler/code/bad-nextjs-export-bug/node_modules/next/dist/server/require.js:77:15)
    at /Users/kevzettler/code/bad-nextjs-export-bug/node_modules/next/dist/export/index.js:382:48
    at Array.map (<anonymous>)
    at /Users/kevzettler/code/bad-nextjs-export-bug/node_modules/next/dist/export/index.js:373:69
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Span.traceAsyncFn (/Users/kevzettler/code/bad-nextjs-export-bug/node_modules/next/dist/trace/trace.js:79:20) {
  code: 'ENOENT'
}

Expected Behavior

More clarity in the error message. What is actually missing? The file app/about/page.tsx exists and renders in next dev

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

HummingMind commented 1 year ago

Next export is not yet available/supported for appDir in next 13 as far as I know. You can track the status on the roadmap page: here

pixelpax commented 1 year ago

Damn. I really need this feature. This is a blocker on my app :/

kevzettler commented 1 year ago

Yeah this is a bummer I wouldn't have used the latest version had I know this was broken. Now I guess I'll port to an earlier version and by the time I migrate I assume export will probably be available in the appDir support

HummingMind commented 1 year ago

You don't have to port to the older version. You can stay on 13. Just don't use appDir. That way you get all the other improvements of v13.

pixelpax commented 1 year ago

You don't have to port to the older version. You can stay on 13. Just don't use appDir. That way you get all the other improvements of v13.

That's fair; I've just already put ~150 hours into structuring my app around functional async server side components, which I can't use in pages/

This is actually the only problem I've encountered so far that seems too in-the-weeds of the build process for me to address. I'll just cross my fingers for a workaround soon 🤞

gyurielf commented 1 year ago

Hello there!

FYI - Seems to be it's supported now: https://github.com/vercel/next.js/pull/47022