Seb-L / pinia-plugin-persist

Persist pinia state data in sessionStorage or other storages.
https://Seb-L.github.io/pinia-plugin-persist/
MIT License
214 stars 37 forks source link

Plugin not working with Nuxt 2 #23

Closed Jamiewarb closed 2 years ago

Jamiewarb commented 2 years ago

Hey there,

I followed the integration instructions in the documentation and am receiving an error.

I've created a reproduction here: https://github.com/hex-digital/nuxt-2/tree/pinia-persist and a PR to see it more easily here (https://github.com/hex-digital/nuxt-2/pull/1)

It's set up by:

buildModules: [
  '@nuxtjs/composition-api/module',
  '@pinia/nuxt',
  'pinia-plugin-persist/nuxt',
];

Steps to reproduce

❯ yarn dev
yarn run v1.22.17
$ nuxt

 FATAL  Package subpath './nuxt' is not defined by "exports" in /Users/jamie/Sites/bignight/fresh-nuxt/node_modules/pinia-plugin-persist/package.json

  at new NodeError (node:internal/errors:371:5)
  at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
  at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
  at resolveExports (node:internal/modules/cjs/loader:482:36)
  at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
  at Function.resolve (node:internal/modules/cjs/helpers:108:19)
  at p (node_modules/jiti/dist/jiti.js:1:52925)
  at Resolver.g [as _require] (node_modules/jiti/dist/jiti.js:1:54200)
  at Resolver.requireModule (node_modules/@nuxt/core/dist/core.js:381:29)

   ╭────────────────────────────────────────────────────────────────────────────────────────────────────╮
   │                                                                                                    │
  1 export default {
   │   ✖ Nuxt Fatal Error                                                                               │
   │                                                                                                    │
   │   Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './nuxt' is not defined by "exports" in   │
   │   /Users/jamie/Sites/bignight/fresh-nuxt/node_modules/pinia-plugin-persist/package.json            │
   │                                                                                                    │
   ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

image

Other Notes

Note that for Nuxt, the Pinia docs say to add @pinia/nuxt to buildModules, but this plugins docs say to add pinia/nuxt. Adding pinia/nuxt as you suggest gives a similar error relating to pinia.

Jamiewarb commented 2 years ago

I imagine the docs may just need to change to demonstrate integrating this plugin via a Nuxt Plugin, unless you'd prefer having a nuxt package, similar to how Pinia has one, that can be added as a buildModule?

What do you think?

Seb-L commented 2 years ago

I'm gonna work on nuxt2 and 3 plugins soon, I just updated the documentation on how to use it with nuxt 2 by creating a nuxt plugin: https://seb-l.github.io/pinia-plugin-persist/