next.js: layout.tsx - Returns server errors if not located in root "app" folder (Crucial)
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
Binaries:
Node: 18.16.1
npm: 9.5.1
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 13.4.10
eslint-config-next: 13.4.10
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.6
Next.js Config:
output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router
Link to the code that reproduces this issue or a replay of the bug
https://galanthus-shiny-xylophone-97xj9r4vp639p49.github.dev/
To Reproduce
Move layout.tsx/jsx inside (website) to re-produce the error. Demo is provided with an URL. check: https://galanthus-shiny-xylophone-97xj9r4vp639p49-3000.preview.app.github.dev/dasd (for error) Move the layout outside to the “app” folder error is gone. Imported global styles not loading after moving the layout file to the “app” folder.
Go to random page /abc to see the server errors:
^[Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: null.
Error: Unsupported Server Component type: Null
at attemptResolveElement (webpack-internal:///(sc_server)/./node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:1421:19)
at resolveModelToJSON (webpack-internal:///(sc_server)/./node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:1627:41)
at Object.toJSON (webpack-internal:///(sc_server)/./node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:1169:28)
at stringify (<anonymous>)
at processModelChunk (webpack-internal:///(sc_server)/./node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:2116:24)
at retryTask (webpack-internal:///(sc_server)/./node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:1882:38)
at performWork (webpack-internal:///(sc_server)/./node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:1920:21)
at Timeout.eval [as _onTimeout] (webpack-internal:///(sc_server)/./node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:1429:28)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
digest: '135229182'
}
Describe the Bug
layout file has to be located in the root of “app” moving it inside a another path like (website), (front-end) will not work.
Expected Behavior
To work inside root, as in different route paths like it used to work in the previous version.
Which browser are you using? (if relevant)
Brave
How are you deploying your application? (if relevant)
Vercel
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 10
- Comments: 40 (6 by maintainers)
@Abdelhadi92 I tried with the example from next-intl with latest nextjs (13.4.16) it picks up the locale layout
👍 It is a critical bug that breaks the whole not-found page for localized apps.
The problem for me is that the
not-found.tsx
requires a root layout atapp/layout.tsx
. But for localization you need a root layout atapp/[lng]/layout.tsx
. You cannot have both because Next will merge them. I tried creating top-level route groups but that didn’t work. This means that currently it’s not possible to have custom 404 pages for localized Next sites… which I consider a critical bug. But as it’s not fixed in the last couple of minor version I’m thinking there should be a solution I’m not aware of…This error happens to me as well, but in my case occurs when i call
notFound
function in a route (page.tsx)Close as there’s no new updates for this issue and few folks confirmed it’s fixed for them. If you still having trouble with the above error, please file a new issue with a reproduction, thanks!
Thanks @huozhi
Yes, it works after upgrading next to 13.4.16.
Latest update fixed this error but layout.tsx and not-found.tsx is not working if inside path like (website), (admin) etc.
For me it also started with 13.4.10 and I still have the error with 13.4.11.
I’m not using turbo.
Only happens for 404 routes.
I’m using i18n and my “root” layout is inside
app/[lng]
. This seems to be the issue. When I create a root layout inapp
the error is gone. But now the language is, of course, not available anymore…I could fix my issue by creating layout.tsx inside app folder. I didn’t have a root layout because i’m using next-int that requires you to have [locale] as root layout
Not using Turbopack at all just regular dev mode. Lets hope this can be reverted or fixed.
Thank you code friend for confirming.