app dir nuxt 4
Hello there, i got to go on nuxt 4 for my next task.
Well i got some issues with the
app directory : instead of displaying "hello world", it display the nuxt welcome page, i guess my app directory did not get detected by nuxt.
here's my config :
My folder structure is in the image below.
5 Replies
Hi @() => "CodingBill";. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, in Nuxt 4 the new default directory structure expects your application source code to be inside an app/ directory at the project root, not inside src/app/. By default, Nuxt sets srcDir to app/ (i.e., <rootDir>/app), and most things are resolved from there. If you set srcDir to src/, then your app directory should be src/assets, src/components, etc., and your app.vue should be at src/app.vue, not src/app/app.vue.
Your current config:
is not correct, because appDir is not a valid Nuxt config option. The correct option is dir.app, and it should be relative to srcDir (or rootDir, depending on your structure).
How to fix:
- If you want to use the new Nuxt 4 structure, your folder tree should look like this:
And your config should be:
- If you want to keep your code in src/, then your structure should be:
And your config should be:
Key points:
- Do not use appDir; use dir.app if you need to customize.
- app.vue should be directly inside your srcDir (e.g., src/app.vue), not nested in src/app/app.vue unless you set dir.app accordingly.
- If Nuxt cannot find app.vue in the expected place, it will show the welcome page instead of your app.
For more details, see the Nuxt 4 directory structure upgrade guide and the srcDir documentation.
If you adjust your structure and config as above, Nuxt should detect your app directory and display your app.vue content as expected.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@180843812204183552> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
1 - @kapa.ai When i got this structure (with no config at all) it works :
2 - But when i have this structure :
With this config :
Only my server works...
Let me check the knowledge base for you again. One moment! :books:
----------------------
Your observation matches the expected Nuxt 4 behavior regarding directory structure and configuration, but there are some important details about how Nuxt resolves directories when you customize them.
1. Default Structure (No Config)
When you use the default structure:
Nuxt automatically detects and uses these directories as intended, with
Only your server works, but the app does not. #### Why? - The Nuxt documentation states that
When you nest your structure under
- With everything under
app/ as the source directory, server/ for Nitro, and shared/ for shared code. No extra configuration is needed, and everything works out of the box New Directory Structure.
---
2. Custom Structure Under src/ with Config
When you move everything under src/:
and use this config:
Issue:Only your server works, but the app does not. #### Why? - The Nuxt documentation states that
dir.app and dir.shared are relative to the srcDir (which defaults to app/ in v4, or . if not set) dir option.
- If you do not set srcDir, Nuxt expects app/ at the project root. By setting dir.app: 'src/app', you are telling Nuxt to look for project/app/src/app, which does not exist.
- Similarly, serverDir is relative to the root by default in v4, so serverDir: 'src/server' is correct if your server code is in src/server.
#### How to Fix
You need to set srcDir to 'src/' so that all your custom directories are resolved relative to src/:
Or, if you want to keep serverDir relative to the project root:
Key Point:When you nest your structure under
src/, you must set srcDir: 'src/' and adjust dir.app and dir.shared accordingly. Otherwise, Nuxt cannot find your app directory and falls back to the welcome page srcDir docs dir docs.
---
Summary:- With everything under
src/, set srcDir: 'src/' and use relative paths for dir.app and dir.shared (e.g., '.' and 'shared').
- If you do not set srcDir, Nuxt expects app/ at the project root.
This should resolve your issue and allow both your app and server to work as expected.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@180843812204183552> Kapa.ai is still learning and improving, please let me know how I did by reacting below.