Import Error in Server Folder
Hi - I have a nuxt3 project that I'm migrating. I have an import in the server folder that seems to want use the appDir as root when resolving a path.
My import is in the for the file
Any ideas on how to hunt down where is getting aded to the resolution path?
I used the codemod to migrate and create the app folder. I do not have any srcDir declarations in my nuxt config.
3 Replies
Hi @kingtimm. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The issue you're encountering is likely due to changes in Nuxt 4's directory structure and how path aliases are resolved after migration.
What's Happening
With Nuxt 4, the default
srcDir
is now app/
, and the ~
alias points to this directory. However, the ~~
alias (double tilde) always points to the project root (rootDir
). In your import:
this should resolve to <rootDir>/server/lib/Transcode
. However, your error message:
shows that app/
is being prepended, which suggests that something is incorrectly resolving ~~
as app/
instead of the project root.
Possible Causes
- Incorrect Alias Resolution: After running the codemod, some tools or plugins (or even custom code) might still be using the old alias resolution logic, causing ~~
to resolve to app/
instead of the root.
- Misconfiguration: If you have any custom alias configuration in your nuxt.config
, tsconfig.json
, or related files, it might be overriding the expected behavior.
How to Debug
1. Check Your Aliases:
- Ensure that ~~
is not redefined anywhere in your config files to point to app/
.
- In Nuxt 4, ~
should point to app/
, and ~~
should point to the project root. You can verify this in your tsconfig.json
and nuxt.config.ts
.
2. Review Directory Structure:
- Make sure your server/
directory is at the project root, not inside app/
(as per the new structure) New Directory Structure.
3. No srcDir
Declaration:
- Since you don't have a srcDir
in your config, Nuxt should use the default (app/
). This is correct for Nuxt 4.
4. Check for Codemod Artifacts:
- Sometimes, automated migrations can leave behind incorrect paths or config. Double-check your tsconfig.json
and nuxt.config.ts
for any unexpected alias or directory settings.
Example: Correct Structure and Import
Your project should look like:
And your import in server/api/transcode.get.ts
should be:
This should work if everything is configured correctly.
Additional Notes
- If you have a custom srcDir
, remember that server/
is now resolved from the root, not from srcDir
New Directory Structure.
- If you want to override this, you can set serverDir
in your config.
Summary
- Double-check your alias configuration and directory structure.
- Make sure server/
is at the root, not inside app/
.
- Ensure no custom config is overriding the ~~
alias.
If after these checks the issue persists, it may be a bug or artifact from the codemod migration. In that case, try restarting your dev server and, if needed, clear .nuxt/
and rebuild.
For more details, see the Nuxt 4 Upgrade Guide.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@643164446289559552> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
It was a codemod artifact that left a tsconfig.json in the server folder that I suppose was not correctly pointed? Deleting that file made it work.