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 not working #14585
Comments
would you please provide a reporduction? |
Not sure if that's related, but (weirdly) I had to explicitly add Let me know whether that works for you. |
Hello @mblachlov24, I think you could try this in the import { defineNuxtConfig } from 'nuxt'
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
modules: [ //instead of buildModules
'@pinia/nuxt'
],
}) then try to remove |
It looks like it's working. However, auto import doesn't work now.
500 |
I don't understand. I know the problem. Please provide a copy |
I updated to RC 8 with @pinia/nuxt@0.4.0 OR @pinia/nuxt@0.3.0 I get with both the following error in development, and the project does not build anymore:
|
@Lyokolux I'm getting the same error when I spin up the development server for the 'first time', but once I kill the process and start it again, the error is gone. Is it the same for you? |
Yes, I am currently experiencing it. The server starts correctly though. I get a EDIT: after relaunching the server a third time, it works 🤔 |
I spotted the following change in |
Would you try clearing your |
It was something related to the cache because it is working now. Updating |
Great. Let's track the root cause in #14604. |
|
Still the same problem for me, I am not able to fix the problem with above solutions. |
What is your error? |
ERROR Cannot start nuxt: Cannot find module 'pinia/dist/pinia.mjs' 14:10:55
|
If you are facing an error, please raise a new issue with a reproduction. You can start from https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz. |
I am not able to reporduce in the stackblitz, but it's happening to me |
I am getting the same error. - ERROR Cannot start nuxt: Cannot find module '@pinia/nuxt' I tried all the above suggestions and still no fix. |
Also a common mistake could be that you installed |
No I have installed pinia/nuxt and not pinia because you can't install pinia on nuxt 3 it gives error from npm |
@typhoon11, I didn't know about that feature. Maybe you can try to remove I can just share to you my setup which is working fine : In "devDependencies": {
"@pinia/nuxt": "^0.4.2",
} In modules: [
'@pinia/nuxt',
], In import { defineStore } from 'pinia'
export const myStore = defineStore({
id: 'my-store',
state: () => {
return {
isReady: false
}
}
}) In my application : const test = myStore()
onMounted(() => {
test.$patch({
isReady: true
})
console.log(test.isReady)
}) Hope it will help. 🙂 |
I will try doing this, btw on which nuxt version you are on I am on the latest rc9 |
I am also on rc-9. I have this config since rc-4 or 5 and didn't experience any issue |
I updated my comment. Also at some point had do |
@henk23 probably because of the pinia location in the project (it's actually included in pinia/nuxt) so import something from 'pinia' can throw an error if didn't recognize as '/node_modules/@pinia/nuxt/node_modules/pinia/dist/pinia.mjs' |
Switching from npm to yarn did the trick for me. I had similar problems when trying to install the pinia persisted state plugin. They were also solved after the switch. |
Had the exact same issue Trying to install pinia didn't work so had to force it with: That solved my problem. |
Just sharing my experience, from what I have tried. There are 2 ways to use pinia with Nuxt.
I tried the first method and my app crash big time no matter what I try to do. But with the 2nd method it is much more easier without any problem. I just run Then I declare using Nuxt plugin with this setup
Then I just use pinia in my composables. Hope this helps |
Update latest It turns out that we need to install both package with the first and second method that I mentioned here. |
I tried this and it worked for me. |
This helped in my case export default defineNuxtConfig({
modules: [
['@pinia/nuxt', { autoImports: ['defineStore'] }], // v 0.4.6
],
alias: {
pinia: process.env.NODE_ENV === 'production' ? '/node_modules/pinia/dist/pinia.mjs' : '/node_modules/@pinia/nuxt/node_modules/pinia/dist/pinia.mjs',
},
}); |
This isn't the correct solution but I am posting it here because it worked for our app (and might help others)... We have are using the following in our package file as dependencies: "@pinia/nuxt": "^0.4.6",
"pinia": "^2.0.27", The app is built with We had the same issue as others (couldn't find the pinia module) and
The app could then start up and handle requests. |
When I restart it, it still gives an error even though it is in import.d.ts. Interesting. settings imports: {
dirs: ['stores'],
},
Uncaught (in promise) ReferenceError: useUserStore is not defined |
header.vue click and ctrl + s fixed. and pnpm dev reload. Same problem go ctrl + s fixed :D |
Had the exact same issue
|
To reliably solve this problem you can do this following steps:
This problem occurs in npm not yarn, if you run |
I am having same issue as @Lyokolux when trying to put stores into compostables. It doesn't appear to work. And yes, pinia is installed and the same stores are working elsewhere just fine.
|
I tried using |
Hey there, I'd suggest we can close this, not being a nuxt issue but an issue on how to properly configure pinia and or upgrade nuxt to the latest versions. Or this there anything in here that nuxt can fix I may have missed? |
For those getting the error while installing, did we add the overrides object to the package.json file? |
I realise people are still having trouble configuring pinia with Nuxt and would love to help solve this. If you are able, would you instead create an upstream issue in the pinia repository? Feel free to tag me and I will do my best to help. Having said that, I don't believe this is an issue with Nuxt so I'm closing here, for now at least. 🙏 |
In my case I started to have error: |
I had this problem too. It came from "nowhere". I have now resolved it after trying all of the above without success. In ny case I decided to try and replicate a working setup from scratch. I started a new project using:-
then as soon as I ran yarn install I got the "name" error! So, the conclusion for me was my Node installation was bad. I ran The moral of the story is stick to using lates LTS. So, after getting myself to node 18.15.0 , running all is well for me. So, my advice is if strange errors like this then check your Node version. Also, dont run this: Always install the version you want! |
Same Node version, same code, at first it worked fine for me, my coworker gets this error. Today I'm working on another project with the same code, and it's my turn to get this error.
Then after I updated nuxt to nuxt 3.8.0 everything worked also not fine!
( I updated nuxt first but it didn't work. ) |
With:
I fixed this by:
|
Hi, I am also experiencing the error is it intended to use both packages 'pinia' and '@pinia/nuxt' when working with nuxt or should '@pinia/nuxt' be sufficient? |
Please add this into your nuxt.config.js/ts
|
Environment
Linux
v16.16.0
3.0.0-rc.8
npm@8.11.0
vite
modules
,buildModules
,colorMode
,typescript
,experimental
,vite
@nuxtjs/tailwindcss@5.3.2
,@nuxtjs/color-mode@3.1.4
,@vueuse/nuxt@9.1.0
@pinia/nuxt@0.4.0
Reproduction
I installed the pinia, added it to buildModule and got an error when starting nuxt.
It worked fine on the RC 6.
Describe the bug
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: