N
Nuxt4w ago
kingtimm

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.
[nitro 9:30:10 PM] ERROR Error: Could not load /home/king/dev/project/app//server/lib/Transcode'
[nitro 9:30:10 PM] ERROR Error: Could not load /home/king/dev/project/app//server/lib/Transcode'
My import is
import useTranscoder from '~~/server/lib/Transcode'
import useTranscoder from '~~/server/lib/Transcode'
in the for the file
server/api/transcode.get.ts
server/api/transcode.get.ts
Any ideas on how to hunt down where
app/
app/
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
kapa.ai
kapa.ai4w ago
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:
import useTranscoder from '~~/server/lib/Transcode'
import useTranscoder from '~~/server/lib/Transcode'
this should resolve to <rootDir>/server/lib/Transcode. However, your error message:
Error: Could not load /home/king/dev/project/app//server/lib/Transcode
Error: Could not load /home/king/dev/project/app//server/lib/Transcode
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:
app/
...
server/
lib/
Transcode.ts
api/
transcode.get.ts
nuxt.config.ts
app/
...
server/
lib/
Transcode.ts
api/
transcode.get.ts
nuxt.config.ts
And your import in server/api/transcode.get.ts should be:
import useTranscoder from '~~/server/lib/Transcode'
import useTranscoder from '~~/server/lib/Transcode'
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: ----------------------
kapa.ai
kapa.ai4w ago
<@643164446289559552> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
kingtimm
kingtimmOP4w ago
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.

Did you find this page helpful?