Cannot load Pinia in Nuxt3
Asked Answered
D

4

10

I am trying to set up Nuxt3 to work with Pinia.

Steps Taken:

  • Started with an active nuxt3 project
  • ran npm install @pinia/nuxt
  • this failed, with a dependency error, so re-ran with npm install @pinia/nuxt --legacy-peer-deps, which worked fine
  • added pinia to my nuxt.config.ts, which now looks like:
import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
    meta: {
        link: [
            {
                rel: "stylesheet",
                href:"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
            }
        ],
      script: [
        { src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js', integrity: 'sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2', crossorigin: 'anonymous' }
      ]
    },
    ssr: false,
    buildModules: ['@pinia/nuxt'],
    base: '/',
})
  • restarted the server
  • got the following error:

GET http://localhost:3000/_nuxt/@id/pinia/dist/pinia.mjs net::ERR_ABORTED 404 (Not Found)

I've been googling around, and can't figure out what's broken here... I tried taking out the 'base' argument in nuxt.config.ts, and that didn't help either. If I take out the pinia declaration everything works fine.

Deen answered 27/6, 2022 at 21:19 Comment(0)
D
18

Resolved by running: npm install pinia @pinia/nuxt @nuxtjs/composition-api --legacy-peer-deps

I guess I was missing the actual pinia library

Deen answered 27/6, 2022 at 22:24 Comment(3)
I used "npm install pinia @pinia/nuxt --legacy-peer-deps "and installed without error. what is purpose of using @nuxtjs/composition-api package?Tilghman
@nuxtjs/composition-api is for Nuxt2 only and enables the use of the composition api. Seems to be useless here.Milliner
I tried the official approach by adding the overrides property to my package.json but was still getting errors. Resolved it by installing like so: npm install pinia @pinia/nuxt --legacy-peer-deps.Sailer
C
5

In the Nuxt docs they suggest adding this to your package.json before running npm install:

"overrides": {
  "vue": "latest"
}
Castorina answered 12/6, 2023 at 15:25 Comment(0)
B
2

i had a same problem and solve it install with yarn add @pinia/nuxt instead npm

Bolzano answered 3/12, 2022 at 20:48 Comment(0)
J
0

NuxtJS DOC

In the NuxtJS DOC ther's a guide that will help you on this.

Jovian answered 7/7, 2023 at 6:59 Comment(1)
adding this results in Override for vue@^3.3.13 conflicts with direct dependencyPromisee

© 2022 - 2024 — McMap. All rights reserved.