Skip to content
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 nuxt version 0.6.0+ causes error when used with pnpm monorepo #2820

Open
kalvenschraut opened this issue Nov 1, 2024 · 12 comments · Fixed by #2821
Open

Pinia nuxt version 0.6.0+ causes error when used with pnpm monorepo #2820

kalvenschraut opened this issue Nov 1, 2024 · 12 comments · Fixed by #2821
Labels
bug Something isn't working has workaround The issue contains a temporary solution to get around the problem ⛰ pkg:nuxt Related to @pinia/nuxt

Comments

@kalvenschraut
Copy link
Contributor

kalvenschraut commented Nov 1, 2024

Reproduction

https://stackblitz.com/~/github.com/kalvenschraut/pinia-nuxt-pnpm-monorepo-issue

Steps to reproduce the bug

To see issue do

pnpm install
pnpm --filter website1 run dev

can then downgrade @pinia/nuxt to 0.5.5 and run same commands to see it working. Can also upgrade to 0.6.1 to verify still not working

pnpm update @pinia/[email protected] -r
pnpm --filter website1 run dev

Expected behavior

Page to load and show the users name from the user store

Actual behavior

image

Additional information

In prod builds on my personal site where I first initial saw this was seeing vueDemi.effectScope is not a function error. Downgrading back to 0.5.5 for now until direction can be given

@kalvenschraut kalvenschraut changed the title Pinia nuxt version 6.0.0+ causes error when used with pnpm monorepo Pinia nuxt version 0.6.0+ causes error when used with pnpm monorepo Nov 1, 2024
@rylanharper

This comment was marked as spam.

@maxdzin

This comment was marked as spam.

@posva

This comment was marked as off-topic.

@posva
Copy link
Member

posva commented Nov 2, 2024

I did some research, and the problem persists even with upgraded Nuxt and pnpm. The cause of the problem is the removal of the alias for pinia in 65031ee
I needed that change to work in other scenarios so I will investigate this further. In the meantime, here is a workaround: add an alias to your nuxt.config so pinia is resolved correctly:

import { fileURLToPath } from 'node:url'
import path from 'node:path'

const rootDir = fileURLToPath(new URL('../..', import.meta.url))

export default defineNuxtConfig({
  modules: [ '@pinia/nuxt'],
  alias: {
   pinia: path.resolve(rootDir, 'node_modules/pinia/dist/pinia.mjs')
  }
});

Or exclude pinia from vite optimization:

export default defineNuxtConfig({
  modules: [ '@pinia/nuxt'],
  vite: {
    optimizeDeps: {
      exclude: ['pinia']
    }
  },
});

@danielroe I would like some help with this matter: in my tests, I have two copies of pinia in non monorepo nuxt applications. I still don't understand why this part of the Pinia module is so flaky, and I suppose it's more of an issue of Vite than Nuxt. But I imagine you have seen this issue often enough to guide me in the right direction (and add a note comment so my future self does not forget 😅)

@posva posva added bug Something isn't working has workaround The issue contains a temporary solution to get around the problem ⛰ pkg:nuxt Related to @pinia/nuxt labels Nov 2, 2024
@posva
Copy link
Member

posva commented Nov 2, 2024

Using the shamefully-hoist=false also works

@posva
Copy link
Member

posva commented Nov 3, 2024

I'm still not 100% sure of the fix being the right solution so I will keep this open until then

@HP8585

This comment was marked as spam.

@posva

This comment was marked as off-topic.

@jaap3
Copy link

jaap3 commented Nov 11, 2024

I've updated @nuxt/pinia to 0.7.0 last week and started running into this issue. Downgrading to 0.6.1 makes everything work again.

Additional data points:

  • I'm also on a monorepo, but using plain npm
  • nuxt: ~3.14.159
  • pinia: ~2.2.6
  • Using nuxt layers, pinia and @nuxt/pinia are installed in the "bottom" layer

EDIT: So 0.6.1 works in development (at least for me), but after a deploy to staging "everything" was broken. Only after downgrading to 0.5.5 did a deployed build work again.

@ibrahimzdmr
Copy link

ibrahimzdmr commented Nov 11, 2024

Hello, today I've updated from v0.5.5 to v0.7.0 and couldn't run the project.

This is the error I'm receiving "[nuxt] [request error] [unhandled] [500] Cannot find module '/.output/server/node_modules/pinia/dist/pinia.mjs' imported from /.output/server/chunks/build/server.mjs"

and when I check the file in node module there is only pinia.prod.cjs file.

nuxt: 3.13.2

also I use pnpm

Thank you

@posva
Copy link
Member

posva commented Nov 15, 2024

I think that to fix this we might release a new version that removes the compatibility with Vue 2.6 but keeps Vue 2.7. This will allow removing some peer dependencies that nom isn't able to support (like other package managers do)

@HP8585
Copy link
Contributor

HP8585 commented Nov 16, 2024

please just fix it whatever changes it takes let it take...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround The issue contains a temporary solution to get around the problem ⛰ pkg:nuxt Related to @pinia/nuxt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants