Home > OS >  Pinia gives module error in terminal when trying to run dev
Pinia gives module error in terminal when trying to run dev

Time:10-10

I setup Pinia on top of fresh Nuxt3 app and start dev server, with exactly these commands in order:

npx nuxi init nuxt-app
cd nuxt-app
npm install
npm install @pinia/nuxt
npm run dev

Dev server runs without any problem. Then, i put this line of code into "nuxt.config.ts";

export default defineNuxtConfig({
  modules: ["@pinia/nuxt"],
});

And, when i again try to connect to dev server, it gives me this error message in terminal:

 ERROR  Cannot start nuxt:  Cannot find module 'pinia/dist/pinia.mjs'                                                                     12:03:55
Require stack:
- C:\Users\user\Documents\github2\nuxt-app\index.js

CodePudding user response:

As mentioned here, there is an issue with NPM not doing it's job properly, here is how you can solve it:

npm i pinia -f

CodePudding user response:

The solution is; downloading pinia dependencies too. So not just the @pinia/nuxt (which pinia website not says about). And how you gonna do this is by typing "install pinia -f".

Let's discuss this:

https://pinia.vuejs.org/ssr/nuxt.html --> This is official pinia nuxt installation page. Here it just says to "install @pinia/nuxt". I don't know if it works for Nuxt but this is not the way to go for Nuxt3. I think this page should've mentioned this issue earlier for Nuxt3 immedietaly but looks like they didn't, and i felt so lost for days looking for the best solution and not the bottom solutions, because i feel like there should have been better way to do this and not forcing it with the bottom commands. Plus, pinia page doesn't even mention that we needed "install pinia". Well, whatever. Nuxt3 needs "install pinia" too, beyond "@pinia/nuxt". If you not, nuxt3 app won't gonna start and give the error on top of this page.

And then, "install pinia" takes us to our second problem, when you try to "install pinia" onto Nuxt3 app, it gives some "ERESOLVE could not resolve" error messages in terminal. So the only solution here for now is to install pinia dependencies BY using "install pinia -f, OR install pinia --legacy-peer-deps, OR install pinia --force"

I think -f can be equal to --force but i don't know exactly.

  • Related