unplugin / unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
MIT License
3.12k stars 193 forks source link

Using pinia preset in Nuxt #402

Open mrleblanc101 opened 1 year ago

mrleblanc101 commented 1 year ago

Describe the bug

I'm not sure how preset work, there is no real documentation on how to auto import everything from Pinia. I tried this, which looked logical from the doc:

export default defineNuxtConfig({
    imports: {
        imports: ['pinia'],
        dirs: ['stores'],
    },
});

But I get this type error:

Type 'string' has no properties in common with type '{ name?: string | undefined; as?: string | undefined; from?: string | undefined; priority?: number | undefined; disabled?: boolean | undefined; meta?: { [x: string]: any; description?: string | undefined; docsUrl?: string | undefined; } | undefined; type?: boolean | undefined; }'.

Reproduction

.

System Info

System:
    OS: macOS 13.4
    CPU: (8) arm64 Apple M1 Pro
    Memory: 711.98 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
  Browsers:
    Chrome: 114.0.5735.133
    Chrome Canary: 117.0.5857.1
    Firefox: 114.0.2
    Safari: 16.5
    Safari Technology Preview: 17.0

Used Package Manager

yarn

Validations

mrleblanc101 commented 1 year ago

Looking at the type definition, I don't see how it's possible to use a preset in Nuxt.

Capture d’écran, le 2023-06-28 à 03 24 01
mrleblanc101 commented 1 year ago

Looking at the Pinia doc, I found that they have their own way of dealing with autoImports: https://pinia.vuejs.org/ssr/nuxt.html#auto-imports

Capture d’écran, le 2023-06-28 à 03 27 12

But why would I wan't to define everything I want to autoImport, isn't the point of Nuxt 3 to auto detect the function used in my code ? I don't want to specify every single function to autoImport in my nuxt.config.js 🤔

mrleblanc101 commented 1 year ago

From what I understand, the preset exist from this PR: https://github.com/antfu/unplugin-auto-import/pull/60 I just don't see how to use it in Nuxt.

lishaobos commented 12 months ago

same as https://github.com/antfu/unplugin-vue-components/issues/657 , you can use vite.plugins reaplace the nuxt default imports