问题一:在nuxt3 中安装pinia时候如果只配置 pinia会报 "peer vue@"^3.2.37" from @nuxt/vite-builder@3.0.0-rc.8"

"npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: example-server-routes@undefined
npm ERR! Found: vue@3.2.37
npm ERR! node_modules/vue
npm ERR!   peer vue@"^3.2.37" from @nuxt/vite-builder@3.0.0-rc.8
npm ERR!   node_modules/@nuxt/vite-builder
npm ERR!     dev @nuxt/vite-builder@"^3.0.0-rc.8" from the root project
npm ERR!   peer vue@"^3.2.0" from element-plus@2.2.15
npm ERR!   node_modules/element-plus
npm ERR!     dev element-plus@"^2.2.15" from the root project
npm ERR!   1 more (nuxt)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev pinia@"^2.0.21" from the root project"

 是因为 配置文件中没有 vue3 的依赖 需要安装vue3 在 package.json

 问题二: Cannot find module 'xxxx\node_modules\pinia\dist\pinia.mjs'

 提示 找不到 pinia

解决方案:

npm install --save pinia @pinia/nuxt pinia-plugin-persist --legacy-peer-deps

 

import { defineNuxtConfig } from 'nuxt';
import { resolve } from 'path';

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  ...
  modules: ['@pinia/nuxt'],
  ...
})

引用方案地址:

Nuxt3+pinia+pinia-plugin-persist(踩坑指南)_梨花炖海棠的博客-CSDN博客

Logo

前往低代码交流专区

更多推荐