import { createPinia } from "pinia";
import persisted from "pinia-plugin-persistedstate";
const pinia = createPinia();
pinia.use(persisted);
export default pinia;
export * from "./useUserInfoStore";
- 发布:2025-01-07 11:12
- 更新:2025-01-07 11:28
- 阅读:105
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows11 23H2
手机系统: Android
手机系统版本号: Android 14
手机厂商: 小米
手机机型: Redmi K50 Pro
页面类型: vue
vue版本: vue3
打包方式: 离线
项目创建方式: CLI
CLI版本号: @vue/cli 5.0.8
示例代码:
操作步骤:
import { createPinia } from "pinia";
import persisted from "pinia-plugin-persistedstate";
const pinia = createPinia();
pinia.use(persisted);
export default pinia;
import { createPinia } from "pinia";
import persisted from "pinia-plugin-persistedstate";
const pinia = createPinia();
pinia.use(persisted);
export default pinia;
预期结果:
import { createPinia } from "pinia";
import persisted from "pinia-plugin-persistedstate";
const pinia = createPinia();
pinia.use(persisted);
export default pinia;
import { createPinia } from "pinia";
import persisted from "pinia-plugin-persistedstate";
const pinia = createPinia();
pinia.use(persisted);
export default pinia;
实际结果:
import { createPinia } from "pinia";
import persisted from "pinia-plugin-persistedstate";
const pinia = createPinia();
pinia.use(persisted);
export default pinia;
/**
* [vite]: Rollup failed to resolve import "destr" from "D:/DataBase/WorkSpace/templete Android_iOS/node_modules/pinia-plugin-
* persistedstate/dist/index.js".
* This is most likely unintended because it can break your application at runtime.
* If you do want to externalize this module explicitly add it to
* `build.rollupOptions.external`
*/
import { createPinia } from "pinia";
import persisted from "pinia-plugin-persistedstate";
const pinia = createPinia();
pinia.use(persisted);
export default pinia;
/**
* [vite]: Rollup failed to resolve import "destr" from "D:/DataBase/WorkSpace/templete Android_iOS/node_modules/pinia-plugin-
* persistedstate/dist/index.js".
* This is most likely unintended because it can break your application at runtime.
* If you do want to externalize this module explicitly add it to
* `build.rollupOptions.external`
*/
bug描述:
使用 pinia-plugin-persistedstate 为 pinia 添加持久化能力时,运行 app 开发环境时报出以下构建错误。
[vite]: Rollup failed to resolve import "destr" from "D:/DataBase/WorkSpace/templete Android_iOS/node_modules/pinia-plugin-persistedstate/dist/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external
亲爱的皂gaigai (作者)
貌似已解决。
报错情况是使用的 pnpm 来执行构建。
找到个相似问题:https://ask.dcloud.net.cn/question/202410,更换成 npm 来构建能够正常构建运行。
亲爱的皂gaigai (作者)
好的,感谢解答,我去试试
2025-01-07 11:40