next.js icon indicating copy to clipboard operation
next.js copied to clipboard

[Appdir] Using app directory inside src directory cause First Load JS shared by all equal 0kb

Open Noki-Asakuri opened this issue 3 years ago • 1 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

  • Operating System:
    • Platform: win32
    • Arch: x64
    • Version: Windows 10 Home Single Language
  • Binaries:
    • Node: 18.12.1
    • npm: N/A
    • Yarn: N/A
    • pnpm: 7.15.0
  • Relevant packages:
    • next: 13.0.3
    • eslint-config-next: 13.0.3
    • react: 18.2.0
    • react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Put app directory inside src directory cause First Load JS shared by all equal 0kb on build

Expected Behavior

First Load JS shared by all not equal 0kb

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://stackblitz.com/edit/vercel-next-js-m3shiy

To Reproduce

  1. Init project with create-next-app with --experimental-app flag
  2. Move both pages and app into src directory
  3. Run next build

Noki-Asakuri avatar Nov 14 '22 07:11 Noki-Asakuri

The reason is that the app-build-manifest.json is empty when using a src dir. When using a src dir the entrypoint.name gets named src/app/page here https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack/plugins/build-manifest-plugin.ts#L198, which cuases the regex in getAppRouteFromEntrypoint to not include the file.

The entrypoints are named the same with or without the srcdir when using pages. https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack/plugins/build-manifest-plugin.ts#L198

Probably same issue #42792

hanneslund avatar Nov 14 '22 10:11 hanneslund

I've recently run into this issue myself & has actually caused me to revert my initial PR beginning an incremental migration to the app directory as this it causes all app directory routes in production builds to throw client-side errors when using some Next.js components.

In my case It is mainly being caused by the use of the Link component but I am unsure if this includes / affects other components that require extra JS logic that is not being built.

Stackblitz to reproduce / show the issue

  1. Run npm run build
  2. Run npm run start
  3. Navigate to /test

NuroDev avatar Nov 20 '22 14:11 NuroDev

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Dec 23 '22 00:12 github-actions[bot]