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

Auto-import engine treats non-component files as components #15447

Closed
MorevM opened this issue Nov 11, 2022 · 5 comments
Closed

Auto-import engine treats non-component files as components #15447

MorevM opened this issue Nov 11, 2022 · 5 comments

Comments

@MorevM
Copy link
Contributor

MorevM commented Nov 11, 2022

Environment

No matter

Reproduction

https://stackblitz.com/edit/github-g7riij?file=nuxt.config.ts

Run npm run dev and check the console.
There are three "components" registered, but actually only one of them is a Vue component.

Describe the bug

The auto-import engine treat any (?) vue/ts file as component and register it.
However, developers may put the types alongside the component, or even they want to put any other file with logic related to component for decomposition purposes.

There should be a more robust check if the file is really a Vue component.
As I can see it breaks nothing but autocomplete..

example-of-wrong-autocomplete

Additional context

No response

Logs

No response

@danielroe
Copy link
Member

This should be resolved in the edge channel, or in the next RC via nuxt/framework#8787.

Let me know if not and I'll reopen.

@MorevM
Copy link
Contributor Author

MorevM commented Nov 11, 2022

@danielroe if this is the only MR related, then I can already say that it will not help.
Please look at the filenames in the reproduction more carefully - there is no .d.ts files at all, just .ts.

I also updated the reproduction to use Nuxt from the Edge channel, and this is still an issue.

I made a picture with points of attention to make it easier to understand what I'm talking about:

points-of-attention

@danielroe
Copy link
Member

Ah. If you are placing .ts files in the components folder, they will be scanned as components. That's intended behaviour. To change this, you can configure extensions:

export default defineNuxtConfig({
  components: [
    {
      path: '~/components',
      extensions: ['.vue']
    }
  ]
})

@MorevM
Copy link
Contributor Author

MorevM commented Nov 11, 2022

@danielroe thanks, it solves the problem.

I noticed it's not documented anywhere. Do you need a docs update in that part?

@danielroe
Copy link
Member

That would be very welcome - thank you.

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

No branches or pull requests

2 participants