question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nuxt 3 Module custom layout style issue

See original GitHub issue

Environment

  • Operating System: Darwin
  • Node Version: v14.18.2
  • Nuxt Version: 3.0.0-rc.4-27605536.8c2c80e
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Please see reproduction example here: https://github.com/sppmstar/nuxt-3-module-layout-vite-bug

Describe the bug

When adding a style block to a custom layout in a Nuxt 3 module, i get the following error:

Screen Shot 2022-06-29 at 14 44 59

If I remove the <style> block, it works fine. See here: https://github.com/sppmstar/nuxt-3-module-layout-vite-bug/blob/master/src/layouts/custom-layout.vue#L7-L11

Additional context

No response

Logs

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
danielroecommented, Aug 10, 2022

You are right, it does need a template, not a string - my mistake.

But you define layouts with definePageMeta, not within component options: https://stackblitz.com/edit/github-7l7hcr.

1reaction
danielroecommented, Jul 28, 2022

This looks like an upstream issue with @vitejs/plugin-vue which is trying to read the virtual template from disk. You can workaround it for the moment by ensuring the template is written to disk:

- const tpl = addTemplate(resolve(layoutsDir, 'custom-layout.vue'))
+ const tpl = addTemplate({
+   src: resolve(layoutsDir, 'custom-layout.vue'),
+   write: true
+ })

Or, even more simply, using your existing file:

- const tpl = addTemplate(resolve(layoutsDir, 'custom-layout.vue'))
- addLayout(tpl, 'custom')
+ addLayout(resolve(layoutsDir, 'custom-layout.vue'), 'custom')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Layouts directory - Nuxt
Every file (top-level) in the layouts directory will create a custom layout accessible with the layout property in the page components.
Read more >
layouts/ · Nuxt Directory Structure
Nuxt provides a customizable layouts framework you can use throughout your application, ideal for extracting common UI or code patterns into reusable layout...
Read more >
Introduction to Nuxt 3 modules - DEV Community ‍ ‍
We are importing our local module here and adding some configuration values like url to make it work as expected.
Read more >
How to set up and customize Tailwind in Nuxt.js - Mattermost
You'll build the front end with Nuxt.js and style it using Tailwind CSS. ... <template> <div class="flex items-center w-3/4 min-h-screen ...
Read more >
Nuxt 3 + Tailwind + Eslint + i18n + Sentry Starter - Localazy
This short tutorial will help you set up a scalable Nuxt 3 ... above is enough to catch the code errors and styling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found