vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
12.72k stars 996 forks source link

Automatic detection of appropriate 'storesDirs' default for Nuxt 4 #2709

Closed nathanchase closed 1 week ago

nathanchase commented 1 week ago

What problem is this solving

Just thought I'd mention that if you are using Pinia with Nuxt ^3.12 and have compatibilityVersion: 4 set (to simulate Nuxt 4.0 functionality), then the use of auto-imports will require an update to the stores path to the new Nuxt 4 directory structure.

It's easy enough to update your nuxt.config.ts to:

pinia: {
  storesDirs: ['./app/stores/**'],
}

but perhaps this is something that the Pinia Nuxt module can detect itself and adjust the storesDirs path accordingly?

Proposed solution

For added developer experience, add some update to the Pinia Nuxt module that will detect Nuxt ^4.0, or compatibilityVersion: 4, and update its default storesDirs configuration accordingly to the new app structure where /app is the default root directory for your Nuxt app.

Describe alternatives you've considered

Manual setting of the config.

cmd430 commented 1 week ago

My stores are auto importing on compatibilityVersion: 4 just fine without me changing anything, all I did after enabling compatibilityVersion: 4 was move my directories (including the store directory) into app/ then ran nuxt dev and everything was happy

Edit: typo'd my stores directory, should indeed read as stores not store

nathanchase commented 1 week ago

My stores are auto importing on compatibilityVersion: 4 just fine without me changing anything, all I did after enabling compatibilityVersion: 4 was move my directories (including the store directory) into app/ then ran nuxt dev and everything was happy

Hmm... I wonder if it's a difference in your store dir name? I use stores, where it sounds like you use store.

I found that all my stores auto-importing failed if I used the new /app dir structure and moved my stores dir into /app, unless I explicitly added the storesDir config to point to the correct location.

nathanchase commented 1 week ago

Well, now that I've created the issue, it doesn't appear to be happening anymore, no matter what I name my store directory. I guess this is a false alarm - or potentially something changed between Nuxt 3.12 patch versions that fixed it.