CodeDredd / pinia-orm

The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.
https://pinia-orm.codedredd.de/
MIT License
452 stars 39 forks source link

Nuxt does not render page if installed via Yarn or NPM #1925

Open daniandl opened 2 months ago

daniandl commented 2 months ago

Environment

playground

Reproduction

https://stackblitz.com/edit/nuxt-starter-c2dhfc

Describe the bug

When calling a repo from within a setup script in Nuxt 3, the page does not load. Cannot read properties of undefined (reading '_s') is displayed in a fullscreen error.

Additional context

This has been an issue for a long time in our codebase, as we use Yarn. Today I decided to create a minimal repro for this, and in the stackblitz you will find the issue. I have taken the nuxt 3 playground code from this repo and just updated Nuxt/Pinia/Pinia ORM to their latest and purposefully left out any lockfiles.

Now make sure you remove node_modules between each run, then either npm install or yarn install. Now run yarn run build or npm run build and then run the node server with node .output/server/index.mjs You will notice the error in both cases.

Now, if you run it with pnpm install --> pnpm build, the app works fine. Again, make sure to clear node_modules and delete any lockfiles each time.

Would love some insight here, as this is extremely frustrating and confusing behavior, that the package manager can play a role in whether our code works in production or not. (Dev mode works for all pkg managers)

Logs

...
[nuxt-app] app:created: 0.073ms
[nuxt-app] vue:setup: 0.002ms
Error: TypeError: Cannot read properties of undefined (reading '_s')
    at useStore (/Users/username/projects/testing/nuxt-app/.output/server/node_modules/pinia/dist/pinia.prod.cjs:572:20)
    at Query.commit (file:///Users/username/projects/testing/nuxt-app/.output/server/node_modules/pinia-orm/dist/index.mjs:801:90)
    at Query.saveElements (file:///Users/username/projects/testing/nuxt-app/.output/server/node_modules/pinia-orm/dist/index.mjs:1349:30)
    at Query.save (file:///Users/username/projects/testing/nuxt-app/.output/server/node_modules/pinia-orm/dist/index.mjs:1340:13)
    at Proxy.save (file:///Users/username/projects/testing/nuxt-app/.output/server/node_modules/pinia-orm/dist/index.mjs:1937:25)
    at setup (file:///Users/username/projects/testing/nuxt-app/.output/server/chunks/build/server.mjs:1022:28)
    at _sfc_main$2.setup (file:///Users/username/projects/testing/nuxt-app/.output/server/chunks/build/server.mjs:1049:25)
    at callWithErrorHandling (/Users/username/projects/testing/nuxt-app/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:85:19)
    at setupStatefulComponent (/Users/username/projects/testing/nuxt-app/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:6122:25)
    at setupComponent (/Users/username/projects/testing/nuxt-app/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:6109:36)
Info: https://vuejs.org/error-reference/#runtime-0
[nuxt-app] vue:error: 0.35ms
[nuxt-app] app:rendered: 0.002ms
...
CodeDredd commented 2 months ago

Ufff waht a bug....trying to look into it tomorrow. That's really odd...