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

@pinia/nuxt Auto import does not work when using srcDir #2447

Closed
suzukey opened this issue Oct 14, 2023 · 2 comments
Closed

@pinia/nuxt Auto import does not work when using srcDir #2447

suzukey opened this issue Oct 14, 2023 · 2 comments
Labels
bug Something isn't working contribution welcome ⛰ pkg:nuxt Related to @pinia/nuxt

Comments

@suzukey
Copy link

suzukey commented Oct 14, 2023

Reproduction

https://stackblitz.com/edit/nuxt-pinia-autoimport-repro1?file=nuxt.config.ts

Steps to reproduce the bug

You can see the error when you open the reproduction link.

  1. Set the srcDir option in nuxtConfig.
  2. Define store in src/stores/[name].ts
  3. Use store from app.vue

Expected behavior

It should be automatically imported from ~~/src/stores/[name].ts = ~/stores/[name].ts.

but, it tries to resolve imports from ~~/stores/[name].ts = ~/../stores/[name].ts.

Actual behavior

stores directory in srcDir (not work)

https://stackblitz.com/edit/nuxt-pinia-autoimport-repro1?file=nuxt.config.ts

stores directory in root (it work)

https://stackblitz.com/edit/nuxt-pinia-autoimport-repro2?file=nuxt.config.ts

Additional information

srcDir Option: https://nuxt.com/docs/api/configuration/nuxt-config#srcdir

Auto-importing directories without any configuration is an attractive feature for me.
I hope it will be resolved.

Note: Sorry, I'm using Google Translate, so my English may be difficult to understand.

@suzukey
Copy link
Author

suzukey commented Oct 14, 2023

addImportsDir(resolver.resolve(nuxt.options.rootDir, storeDir))

My guess is that this line should be srcDir (default: rootDir)

if (options.storesDirs) {
  for (const storeDir of options.storesDirs) {
-   addImportsDir(resolver.resolve(nuxt.options.rootDir, storeDir))
+   addImportsDir(resolver.resolve(nuxt.options.srcDir, storeDir))
  }
}

@posva posva added bug Something isn't working ⛰ pkg:nuxt Related to @pinia/nuxt contribution welcome labels Oct 14, 2023 — with Volta.net
Copy link
Member

posva commented Oct 14, 2023

I think what you are suggesting is the right direction. Worth doing a few extra tests

@posva posva closed this as completed in dd90708 Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contribution welcome ⛰ pkg:nuxt Related to @pinia/nuxt
Projects
None yet
Development

No branches or pull requests

2 participants