Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nextjs 13: Can't resolve 'src/app/dashboard/layout.tsx' (deleted optional layout)

So I decided to create a new Nextjs 13.4.5 project with an app directory.

I created a new dashboard directory inside my app directory and then created page and layout component in the dashboard directory. It worked fine, there was two layout component: one was the root layout in the app directory, and the other one is the layout.tsx I created in the dashboard directory

Eventually I decided to delete the layout.tsx in the dashboard directory because I wanted to use only root layout, but an error occurred:

./
Module not found: Can't resolve '/myproject/src/app/dashboard/layout.tsx'

https://nextjs.org/docs/messages/module-not-found

I have searched in my project for any import statements or dynamic imports that reference the deleted dashboard/layout.tsx, but there is no reference

here is my tsconfig file:

{
 "compilerOptions": {
  "target": "es5",
  "lib": ["dom", "dom.iterable", "esnext"],
  "allowJs": false,
  "skipLibCheck": true,
  "strict": true,
  "forceConsistentCasingInFileNames": true,
  "noEmit": true,
  "esModuleInterop": true,
  "module": "esnext",
  "moduleResolution": "node",
  "resolveJsonModule": true,
  "isolatedModules": true,
  "jsx": "preserve",
  "incremental": true,
  "plugins": [
  {
    "name": "next"
  }
],
"paths": {
  "@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

The whole problem is that when you create a new directory for a new page if you don't create layout.tsx inside that directory everything works fine.

but if you create a layout component inside that route directory and then delete it, Nextjs won't be able to render that route without its layout component and this is kinda weird.

Is there any way to solve this? because I don't wanna create an useless layout component for my route

like image 701
Carl Avatar asked Nov 30 '25 01:11

Carl


1 Answers

I had the exact same issue and deleting the .next folder worked for me! Thanks @imjared for that answer!

like image 193
sina-sche Avatar answered Dec 01 '25 14:12

sina-sche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!