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.

Autoimport components dir

See original GitHub issue

Environment


  • Operating System: Linux
  • Node Version: v17.6.0
  • Nuxt Version: 3.0.0-27458584.91fd16a
  • Package Manager: yarn@1.22.18
  • Builder: vite
  • User Config: privateRuntimeConfig, app, components, nitro, srcDir, build, buildModules, modern, tailwindcss, meta
  • Runtime Modules: -
  • Build Modules: @nuxtjs/tailwindcss@5.0.2

Reproduction

Describe the bug

when i trying to start my project with new version of nuxt 3 i have error:

  • [Vue warn]: Failed to resolve component: NavLink 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

my nuxt.config.ts:

import { defineNuxtConfig } from 'nuxt3';

export default defineNuxtConfig({
	privateRuntimeConfig: {
		secretJWT: process.env.SECRET_JWT,
	},
	app: {
		buildAssetsDir: 'assets/',
	},
	components: {
		global: true,
		dirs: ['~/components'],
	},
	nitro: {
		output: {
			dir: 'build',
		},
		externals: {
			inline: ['uuid'],
		},
	},
	srcDir: 'src',
	build: {
		splitChunks: {
			pages: true,
			layouts: true,
		},
	},
	buildModules: ['@nuxtjs/tailwindcss'],
	modern: true,
	tailwindcss: {
		configPath: '~~/tailwind.config.js',
		viewer: false,
	},
	meta: {
		title: 'Santrek Admin',
		link: [
			{
				rel: 'icon',
				href: '/favicon.svg',
				type: 'image/svg+xml',
			},
		],
	},
});

Additional context

Logs

-

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Teranodecommented, Mar 19, 2022

@mihail727 do this instead for components:

import { defineNuxtConfig } from 'nuxt3'

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
    hooks: {
        'components:dirs' (dirs) {
            dirs.push({
                path: '~/components'
            })
        }
    },
    components: {
        global: true
    },
})

@duckies yea I can also see this issue, in the stackblitz repo, use @/components as that one is working as ~/components isn’t for the array

2reactions
duckiescommented, Mar 18, 2022

I’m encountering a similar issue where component resolution is failing when using a non-default srcDir. Reproduction.

You can temporarily fix this by appending srcDir to your component directories, e.g.

export default defineNuxtConfig({
  srcDir: 'src/',
  components: ['~/src/components']
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to auto import Components in Source Content folder?
So, how to auto import such component inside content folder? I tried this in nuxt.config.ts : (It doesn't work). import { defineNuxtConfig } ......
Read more >
The components Property - Nuxt
Nuxt 2.13+ can scan and auto import your components. ... With components: true , by default the ~/components directory will be included.
Read more >
Is there a way to auto import components? : r/sveltejs - Reddit
Instead of doing the imports manually , is there a way to automatically import all of the components from a certain directory? https://i.imgur....
Read more >
How to auto import several components in Nuxt?
I then import these components into a page component/template by doing this: import components from '@/components/blocks'; export default { ...
Read more >
auto-import-global-components - npm
Automatically searches for exported components in folders you specify through plugin-registration in webpack.config. ... Each component can have ...
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