prazdevs / pinia-plugin-persistedstate

💾 Configurable persistence and rehydration of Pinia stores.
https://prazdevs.github.io/pinia-plugin-persistedstate/
MIT License
2.13k stars 121 forks source link

Failed to resolve entry for package "pinia-plugin-persistedstate" #322

Closed SWDevStudio closed 2 months ago

SWDevStudio commented 2 months ago

Are you using Nuxt?

Describe the bug

Can you help identify the problem? I don't quite understand the cause. I tried installing the Nuxt plugin separately as well as together with the regular plugin, but I always encounter the same error.

I followed the instructions and installed the plugin for Nuxt

npm i -D @pinia-plugin-persistedstate/nuxt

export default defineNuxtConfig({
  modules: [
    "@nuxtjs/tailwindcss",
    // Pinia
    "@pinia/nuxt",
    '@pinia-plugin-persistedstate/nuxt',
    // ----
    '@vueuse/nuxt',
  ],

  runtimeConfig: {
    public: {
      backendUrl: process.env.NUXT_PUBLIC_BACKEND_URL,
      frontendUrl: process.env.NUXT_PUBLIC_FRONTEND_URL,
    },
  },

  imports: {
    autoImport: false,
    dirs: ["./utils"],
  },

  experimental: {
    asyncContext: true,
  },

  devtools: { enabled: true },

  routeRules: {
    '/api/**': { proxy: { to: process.env.NUXT_PROXY_BACKEND_URL + '/api/**' } },
    '/storage/**': { proxy: { to: process.env.NUXT_PROXY_BACKEND_URL + '/storage/**' } },
    '/sanctum/csrf-cookie/': {
      proxy: {
        to: process.env.NUXT_PROXY_BACKEND_URL + '/sanctum/csrf-cookie'
      }
    }
  },

  compatibilityDate: "2024-08-07"
});

I received an error in the console. Pre-transform error: Failed to resolve entry for package "pinia-plugin-persistedstate". The package may have incorrect main/module/exports specified in its package.json.

Also, when trying to access the site, I get

[vite-node] [plugin:vite:import-analysis] [ERR_RESOLVE_PACKAGE_ENTRY_FAIL] /node_modules/@pinia-plugin-persistedstate/nuxt/dist/runtime/plugin.mjs

import { persistedState } from 'S:/work/nuxt/site/node_modules/@pinia-plugin-persistedstate/nuxt/dist/runtime/storages';
import { createPersistedState } from "pinia-plugin-persistedstate";
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
export default defineNuxtPlugin((nuxtApp) => {
  const {
    cookieOptions,
    debug,
    storage
  } = useRuntimeConfig().public.persistedState;
  const pinia = nuxtApp.$pinia;
  pinia.use(createPersistedState({
    storage: storage === "cookies" ? persistedState.cookiesWithOptions(cookieOptions) : persistedState[storage],
    debug
  }));
});

My package.json

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview"
  },
  "devDependencies": {
    "@iconify/vue": "^4.1.2",
    "@nuxtjs/tailwindcss": "^6.1.3",
    "@pinia-plugin-persistedstate/nuxt": "^1.2.1",
    "@pinia/nuxt": "^0.5.3",
    "@tailwindcss/forms": "^0.5.2",
    "@vueuse/core": "^10.11.0",
    "@vueuse/nuxt": "^10.11.0",
    "daisyui": "^4.12.10",
    "nuxt": "^3.0.0"
  },
  "dependencies": {
    "@headlessui/vue": "^1.7.22",
    "@nuxtjs/proxy": "^2.1.0",
    "pinia": "^2.2.1",
    "vue-toast-notification": "^3.1.2"
  }
}

Reproduction

https://stackblitz.com/edit/nuxt-starter-iztozi?file=package.json,nuxt.config.ts

System Info

Windows 10, node 20.12.0

Used Package Manager

npm

Validations

raishid commented 2 months ago

same. i when build nuxt project error commonjs. i did revert to old version

SWDevStudio commented 2 months ago

same. i when build nuxt project error commonjs. i did revert to old version

How old of a version did you revert to?

davesawatzky commented 2 months ago

same thing happening here with the nuxt plugin.

luifermartinez-reservandonos commented 2 months ago

same with me, few hours ago it works normally, then when i run npm install failed

I have to use the previous version

luifermartinez-reservandonos commented 2 months ago

same. i when build nuxt project error commonjs. i did revert to old version

How old of a version did you revert to?

i use @pinia-plugin-persistedstate/nuxt@1.2.1 and it works perfectlly. Must be the exact version

davesawatzky commented 2 months ago

I'm using 1.2.1 and am having this issue. It worked fine a couple of hours ago.

arnonrdp commented 2 months ago

Same issue here, gentlemen. I am using 3.2.1. What are you guys doing?


UPDATE:

Downgrade to 1.2.1 worked for me.

raishid commented 2 months ago

This error on 3.2.2

Ryan-santos commented 2 months ago

I added the pinia-plugin-persistedstate package in version 3.2.1 to temporarily resolve the error in my Nuxt project

npm i pinia-plugin-persistedstate@3.2.1

davesawatzky commented 2 months ago

Installed @pinia-plugin-persistedstate/nuxt@1.2.1 with pinia-plugin-persistedstate@3.2.1

This seems to be working.

trspro67 commented 2 months ago

This is working for me: @pinia-plugin-persistedstate/nuxt@1.2.1 pinia-plugin-persistedstate@3.2.1

P2K0 commented 2 months ago

323

This is working for me: pinia-plugin-persistedstate@3.2.1

julianaputra commented 2 months ago

This is working for me: @pinia-plugin-persistedstate/nuxt@1.2.1 pinia-plugin-persistedstate@3.2.1

@trspro67 still not working for me. did you install these 2 plugins in your project? can I see your nuxt.config?

davesawatzky commented 2 months ago

I installed both with pnpm, but only @pinia...@1.2.1 is a nuxt module and included in nuxt.config.

julianaputra commented 2 months ago

I installed both with pnpm, but only @pinia...@1.2.1 is a nuxt module and included in nuxt.config.

@davesawatzky thanks for the reply, how to use persist in pinia store now? when I remove @pinia-plugin-persistedstate/nuxt module from nuxt.config. I got error "persistedState is not defined"

davesawatzky commented 2 months ago

Keep the @pinia module in nuxt config. pinia-plugin-persistedstate@3.2.1 is only installed through npm and in package.json

export default defineNuxtConfig({ modules: [ '@pinia-plugin-persistedstate/nuxt' ], })

prazdevs commented 2 months ago

I'm currently working on v4 and accidentaly published an alpha as "latest" so rushed a republish of v3. Thing is tsup changed the extensions and defaulting to .js instead of .mjs for ESM.

This should be resolved in 3.2.3.

Sorry for the inconvenience. 😌