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

TypeScript5.0+ moduleResolution bundler breaks types import #64

Open jamessawyer opened 1 year ago

jamessawyer commented 1 year ago

I created a new vue-ts project using pnpm create vite@latest my-app --template vue-ts, then I add pinia & pinia-plugin-persist deps。I set up typescript config by the doc, when i import pinia-plugin-persist, vscode will raise an error:

Could not find a delaration file for module pinia-plugin-persist.
There are types at '/xxx/my-app/node_modules/.pnpm/pinia-plugin-persist/dist/index.d.ts', but this result could not be resolved when respectiong package.json "exports". The 'pinia-plugin-persist' library may need to update its package.json or typings.

Here is my tsconfig.json file:

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,

    "types": ["pinia-plugin-persist"]
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

To fix this bug, I have to change the config:

--     "moduleResolution": "bundler",
++    "moduleResolution": "node",

Please support typescript 5.0+!

May be this link clarifies the problem more clean: Add the types condition to the package.json#exports

Tricker39 commented 1 year ago

I encountered the same problem,then I use 'pinia-plugin-persistedstate' instead

jamessawyer commented 1 year ago

I encountered the same problem,then I use 'pinia-plugin-persistedstate' instead

If I mitigate to 'pinia-plugin-persistedstate' lib, anything should pay attention to? @Tricker39