Exploring the intricacies of nested directories with Nuxt 3 and Vite

I'm looking to implement nested directory functionality in Nuxt 3 beta with Vite.

In Nuxt 2, I successfully used the following configuration in (nuxt.config.js):

components: [
{
  path: '~/components', // will get any components nested in let's say /components/test too
  pathPrefix: false,
},],

My directory structure looks like this:

| components
 - Header.vue
 - Footer.vue
 | sections
  - HeroSection.vue

However, when I try to use <HeroSection/> in pages/index.vue, I encounter the following error:

[Vue warn]: Failed to resolve component: HeroSection
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
Invalid value used as weak map key

Is this feature no longer supported in Nuxt 3? Is there another way to configure it now? I couldn't find any relevant information in the documentation.

Thanks <3

Answer №1

When utilizing nested directories, it is necessary to prefix the directory name to the component:

<template>
  <SectionsHeroSection />
</template>

This approach simplifies the component naming process:

- components
    Header.vue
    Footer.vue
  - Sections
      Hero.vue

Resulting in a cleaner way to reference components:

<template>
  <SectionsHero />
</template>

For further information, refer to the documentation:

Answer №2

As I was going through the documentation, I stumbled upon this piece of code:

import { join } from 'pathe'
import { defineNuxtModule } from '@nuxt/kit'

export default defineNuxtModule({
  hooks: {
    'components:dirs'(dirs) {
      // Include the ./components directory in the list
      dirs.push({
        path: join(__dirname, 'components'),
        prefix: 'awesome'
      })
    }
  }
})

However, it appears that it doesn't function properly with the following configuration:

hooks: {
    'components:dirs'(dirs) {
      // Add ./components directory to the list
      dirs.push({
        path: join(__dirname, 'components/sections'),
        prefix: false
      })
    }
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue: The element [undefined] is not recognized as a valid child of the <Routes> component. Only <Route> or <React.Fragment> components are allowed as children of the <Routes

I am facing an issue while trying to upgrade react-router-dom from v5 to v6. The error message I receive is as follows: Error: [undefined] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragm ...

Trigger AngularJS functionality upon the completion of loading a Partial routed by Express

I'm fairly new to AngularJS and recently ran into an issue that's been keeping me up at night... Our application is built on node.js and express, with all partial routing handled by Express. The problem I'm facing is this: Whenever I load ...

Alignment issue with ThreeJS Collada file

I'm currently diving into the world of ThreeJS and I am experimenting with loading collada files into a viewer. My journey began by replicating the code from the Elf colladaLoader demo. I successfully managed to display the model inside an 800px squa ...

JavaScript does not recognize the $ symbol

Firebug is indicating that there is an issue with the $ variable not being defined. I have a basic index.php page that uses a php include to bring in the necessary content. The specific content causing the error is shown below: <script type="text/jav ...

Discover the color value within an array that begins with the "#" symbol

In my PHP code, I have written a function that extracts values from a CSS file and creates an array. Now, I need to loop through this array and create another array that only contains color values (strings starting with #). The challenge is that the length ...

Heroku deployment failed: Push rejected due to lack of a Cedar-supported application

Trying to deploy my 3D game (created with three.js) on a Heroku server has brought up an issue. After running the command "git push heroku master," I encountered the following problem: Initializing repository, done. Counting objects: 252, done. Delta com ...

Add a text description to the textarea when you upload an image

I have a Vue.js file upload feature that I am enhancing by adding a textarea for users to include a description about the uploaded file. Despite my efforts, I am struggling to make this functionality work as intended. The ultimate goal is to send these fil ...

Aligning text vertically to the top with material UI and the TextField component

Seeking guidance on adjusting vertical alignment of text in <TextField /> const styles = theme => ({ height: { height: '20rem', }, }); class Foo extends React.component { ... <TextField InputProps={{ classes: ...

Incorporating external API information into Google Maps

My current challenge involves creating a polygon on Google Maps using data obtained from an external API found at . Upon analyzing the API response, the following information is provided: { "id": 28, "name": "Local spots", "description": "", "isprivate": ...

dividing JavaScript files in the three.js game development platform

After spending two years teaching myself unity/c#, I believe I have the coding skills to transition from an engine to a framework for better control over the environment. As I started working on first person environment features, I wanted to organize my co ...

Can the conventional HTML context menu be swapped out for a link context menu instead?

Currently, I am working on developing a custom linkbox component that is similar to the one found on this page: Here is an example of the code: export const Linkbox = ({}) => { const linkRef = useRef(null); return ( // eslint-disable-next-l ...

Why isn't the page redirecting if the query is unable to locate the user?

Why does the application freeze when it fails to find a user, instead of redirecting to the main page? How can this issue be resolved? User.findOne({_id: userid}, function(err, user) { if(err) { res.redire ...

Vue.js: When Props Become Undefined

After running this code, the output shows "undefined". Child component export default { porps: [ 'idx' ], mounted () { console.log(this.idx) }, } //BambooPage.vue Parent component <template> <div class="bamboo"& ...

Refresh the table following the removal of an item

I am currently working on displaying server data in a table. The delete function is functioning properly, but the deleted item only disappears from the table after refreshing the page. Is there a way to trigger a re-render of the component after deleting a ...

The query entered by the user to search the reddit API

Using Reddit's API search function has been a game-changer for me. I'm still learning the ropes of javascript, and it seems like my code is running the API search function before the user even enters their query. HTML: <div id="site-content" ...

HTML5 video player with secondary playlist

Looking for a videoplayer setup where there are two playlists, but only one can play at a time. When choosing a video from the first list initially, nothing happens. However, after selecting a video from the second list, the first list starts working. HTM ...

Struggling to traverse through intricate layers of nested objects in React and showcasing them without going crazy

Dealing with an API that returns data structured in deeply nested objects has been a challenging task. The goal is to extract specific data from these nested objects and then display them within a React project. Despite numerous attempts, finding a simple ...

Creating synchronicity in your code within the useEffect hook

Is there a way to ensure that my function is fully completed before moving on, even though it's not recommended to add async to useEffect? Take a look at this code snippet: useEffect( () => { const RetrieverDataProcess = async () => ...

The automatic opening of a modal in a Livewire component is not functioning as expected

I am having trouble displaying a modal when my component initializes. I have tried using $this->emit('show) to open the modal When I add a button in my view, the emit('show') works! However, I want the modal to be automatically shown whe ...

Tips for executing JavaScript code within a component

Looking to incorporate a parallax effect into an HTML element in my template. Have the code written, but uncertain of where to place it so that it runs each time the page is scrolled. let pos = document.body.scrollTop; document.getElementById('parall ...