Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning from NuxtLayout: Your project has layouts but the <NuxtLayout /> component has not been used. #24912

Closed
Tracked by #82
doantu05150 opened this issue Dec 27, 2023 · 37 comments · Fixed by #25008
Closed
Tracked by #82

Comments

@doantu05150
Copy link

doantu05150 commented Dec 27, 2023

Environment

package.json

{ "nuxt": "^3.9.0", "typescript": "^5.2.2", "vue": "3.4.0-rc.3", "vue-router": "latest" }

Reproduction

I upgraded Nuxt from 3.8.2 to 3.9.0

Describe the bug

I upgraded to the latest Nuxt version (3.9.0), Vue (3.4.0-rc.3), and the latest vue-router, but I'm getting a warning.

image

There's no error, but rather annoying.

Additional context

Only my app.vue file contains <NuxtLayout> component. Here is my app.vue file:

image

Logs

[Vue warn]: Component LayoutLoader is missing template or render function.
[Vue warn]: Component LayoutLoader is missing template or render function.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.
[Vue warn]: Component LayoutLoader is missing template or render function.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.
[Vue warn]: Component LayoutLoader is missing template or render function.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.
Copy link
Contributor

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@doantu05150
Copy link
Author

I tried reproducing a demo using the latest version, but I couldn't replicate the bug. The problem might be related to the upgrading process rather than the current version.

@daver987
Copy link

I have got the same issued when I updated one of my projects as well, I'm still trying to track down what the guilty culprit is, I will let you know if I get it figured out.

@chris-visser
Copy link
Contributor

Same here. Removing my .nuxt folder fixes it for me. (did'nt even need restart the app). Looks to me like it somehow loses track of app.vue

@daver987

This comment was marked as off-topic.

@waleedtariq109
Copy link

I'm also facing the same issue as well i don't know why this issue is closed even though it's a nuxt 3 bug.

[Vue warn]: Component LayoutLoader is missing template or render function.
[Vue warn]: Component LayoutLoader is missing template or render function.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.
[Vue warn]: Component LayoutLoader is missing template or render function.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.
[Vue warn]: Component LayoutLoader is missing template or render function.
[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.

@agracia-foticos
Copy link

Same issue!!!

@manniL
Copy link
Member

manniL commented Dec 28, 2023

@waleedtariq109 Please provide a reproduction then - happy to reopen the issue if you can provide one 👍🏻

@armenr

This comment was marked as duplicate.

@manniL
Copy link
Member

manniL commented Dec 28, 2023

@armenr Without a reproduction we can't do much here. Also, no full-blown project is needed (and actually discouraged as the reproduction should be minimal) 😋

@chris-visser
Copy link
Contributor

chris-visser commented Dec 28, 2023

I found a consistent reproduction! Here's the link https://github.com/chris-visser/layout-not-used

Reproduction NuxtLayout component not used

  1. Install dependencies. (I've used pnpm). Also I've used an older project with a previous version (3.8) and upgraded it to 3.9. Not yet checked with a fresh fully up to date install
  2. Start the app using pnpm dev
  3. Restart laptop (I'm using Windows)
  4. When reinstalling or removing the nuxt folder, the warning disappears

It looks like it looses references / symlinks on laptop restart?

One other note. Not sure if related, because it might be my IDE

When adding a new component my PyCharm IDE doesn't recognize that new component's auto import
When using in another place after that it does somehow recognize it. This behavior is consistent
everywhere in the app (layouts, pages and other components)

Screenshot 2023-12-28 131947

@Smart-Ace-Designs
Copy link

If it helps, this only happens for me if I use Vuetify with a project and more specifically the "vuetify-nuxt-module". I cannot get it to happen with a generic out-of-the-box Nuxt project or one with, for example, Nuxt UI added to it.

@L422Y
Copy link
Contributor

L422Y commented Dec 28, 2023

I am using a single layout (default)

image image

It seems like in some cases an error in the application will prevent _isNuxtLayoutUsed from being set at all

image

Not sure if this helps but I thought it couldn't hurt.

@cropr
Copy link

cropr commented Dec 29, 2023

After some testing. It is an issue of Nuxt 3.9, it is not present Nuxt 3.8

Steps to reproduce:

<template>
  <NuxtLayout>
    <NuxtPage />
  </NuxtLayout>
</template>

@daver987

This comment was marked as off-topic.

@productdevbook

This comment was marked as duplicate.

@Aareksio
Copy link
Contributor

Aareksio commented Dec 30, 2023

Not sure if reproduction is still needed, but here is one without 3rd party libs:
https://stackblitz.com/edit/github-pbst5v

[nuxt] Your project has layouts but the `<NuxtLayout />` component has not been used.

@CharlesBT

This comment was marked as duplicate.

@purpxd

This comment was marked as duplicate.

@nosizejosh

This comment was marked as duplicate.

@manniL
Copy link
Member

manniL commented Jan 1, 2024

Please stop posting "+1" or "me too". Instead, simply 👍🏻 the issue!

If you have more info to add (e.g. another case/reproduction/...), feel free to do so though.

Also important to note: This does not break any behavior. It is just a warning and won't impact your app except logging this in dev.

@sharpprahs
Copy link

sharpprahs commented Jan 7, 2024

worked for me: 1) delete .nuxt 2) add <NuxtLayout> <NuxtPage/> </NuxtLayout>

@devtrex007
Copy link

Make NuxtLayout top tag in your app.vue it will fix that issue.

image

@mabutalid-kroma
Copy link

This issue seems to happen when you use navigateTo() in the global middleware

@ndro
Copy link

ndro commented Feb 5, 2024

@mabutalid-kroma me too

I didn't get any warning until adding middleware with navigateTo('/)

app.vue

<template>
  <NuxtLayout>
    <NuxtPage />
  </NuxtLayout>
</template>

layouts / default.vue

<template>
  <div>
    <slot />
  </div>
</template>

Trying middleware from Docs
middleware / test.ts

export default defineNuxtRouteMiddleware((to, from) => {
  if (to.params.id === '1') {
    return abortNavigation()
  }
  // In a real app you would probably not redirect every route to `/`
  // however it is important to check `to.path` before redirecting or you
  // might get an infinite redirect loop
  if (to.path !== '/') {
    return navigateTo('/')
  }
})

then some pages

<template>
  <div>
    <h1>Tes Page</h1>
  </div>
</template>

<script setup lang="ts">
definePageMeta({
  middleware: ["test"]
})
</script>

My environment

"nuxt": "^3.9.3",

with

node v20.11.0

and yes, for my case, this is just warning didn't break application

@mrnasil
Copy link

mrnasil commented Feb 5, 2024

Any update?

[nuxt] Your project has layouts but the <NuxtLayout /> component has not been used.

@danielroe
Copy link
Member

Your issue may be resolved in 3.10.1. If not, please open a new issue with reproduction.

@gemyago
Copy link

gemyago commented Feb 6, 2024

Upgraded to 3.10.1, same issue. I could only fix it by downgrading to 3.8.

@Oscar2av
Copy link

Oscar2av commented Feb 11, 2024

Same issue here, I am using Nuxt 3.10.0. The problem only appears while using navigateTo inside a middleware.

@fmichenaud
Copy link

No longer having the issue on 3.10.2

@Patrity
Copy link

Patrity commented Feb 19, 2024

Still encountering this issue as of 3.10.2

  "dependencies": {
    "@heroicons/vue": "^2.1.1",
    "@nuxtjs/supabase": "^1.1.6",
    "@nuxtjs/tailwindcss": "^6.11.4",
    "@nuxtjs/turnstile": "^0.6.3",
    "@pinia-plugin-persistedstate/nuxt": "^1.2.0",
    "@pinia/nuxt": "^0.5.1",
    "@tailwindcss/forms": "^0.5.7",
    "@vueuse/nuxt": "^10.7.2",
    "nuxt": "^3.10.2",
    "nuxt-headlessui": "^1.1.5",
    "vue": "^3.4.19",
    "vue-router": "^4.2.5"
  },

@pavloskafritsas
Copy link

pavloskafritsas commented Feb 20, 2024

I'm also having the same issue (using the latest nuxt version: 3.10.2)

here is my App's structure:

image

here is my browser's console output:

image

edit: I found the issue that triggers the warning.
PLayout is a custom wrapper that provides some teleport slots.
To ensure the teleport slots are available before the page components are loaded, I m using a var that I manually set to true via PLayout's onMounted hook. This flag controls the v-if of the PLayout's default slot (where the NuxtPage component renders).

If I remove the flag, the NuxtPage is available right from the start and the warning disappears.

@Dino-Kupinic
Copy link

For me the problem was that i forgot <slot /> in my default layout.

@pavloskafritsas
Copy link

IMO, this check should run when the page has finished loading, so that v-if conditions can be evaluated first, before this check applies.

@FelixBecquart1990
Copy link

FelixBecquart1990 commented Feb 27, 2024

The error was explained with more details in error.stack. Thanks to that, I found my error and was able corrected it.

To get the error.stack: create at the same level that app.vue an error.vue.

<script setup lang="ts">
import type { NuxtError } from '#app'

const props = defineProps({
  error: Object as () => NuxtError
})

const handleError = () => clearError({ redirect: '/' })
</script>

<template>
  <div>

    <div>{{ error.statusCode }}</div>

    <div>{{ error.message }}</div>

    <div v-html="error.stack"></div>

  </div>
</template>

@abarke
Copy link
Sponsor

abarke commented May 6, 2024

I'm also getting this error in a Nuxt Ionic App. In this case I am not using NuxtPage, because I'm using ion-router which I assume uses NuxtPage. Any way to disable this false positive warning?

image

------------------------------
- Operating System: Windows_NT
- Node Version:     v22.1.0
- Nuxt Version:     3.11.2
- CLI Version:      3.11.1
- Nitro Version:    2.8.1
- Package Manager:  pnpm@8.15.5
- Builder:          -
- User Config:      devServer, ssr, css, modules, electron, ionic, vite, nitro
- Runtime Modules:  @nuxtjs/ionic@0.13.1, nuxt-electron@0.7.0
- Build Modules:    -
------------------------------

Copy link
Member

IonRouter does not use NuxtPage. This should be worked around in https://github.com/nuxt-modules/ionic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.