Laravel+Vue3项目集成Pinia报错:export 'default'未在'vue'中找到
This error happens because your code or a dependency is trying to import Vue as a default export—something that doesn’t exist in Vue3, which uses createApp instead of the global Vue instance. Your main initialization code is correct, so the issue lies elsewhere in your project.
Here are the steps to fix it:
Verify Pinia version compatibility
Make sure you’re using Pinia v2.x, which is built for Vue3. Check yourpackage.jsonor runnpm list piniain your terminal. If you have Pinia v1 (for Vue2), upgrade with:npm install pinia@latestAudit your Pinia store files
Look for any imports likeimport Vue from 'vue'in your store definitions. Pinia v2 doesn’t require this. A correct Vue3-compatible store should look like this:import { defineStore } from 'pinia' export const useAuthStore = defineStore('auth', { state: () => ({ user: null, token: localStorage.getItem('token') || null }), actions: { login(token, user) { this.token = token this.user = user localStorage.setItem('token', token) }, logout() { this.token = null this.user = null localStorage.removeItem('token') } } })Check third-party dependencies
If you’re using any authentication plugins or other Vue packages, confirm they’re compatible with Vue3. Older packages may still attempt to import the default Vue export. Update these packages or replace them with Vue3-friendly alternatives.Clear cache and rebuild
Sometimes cached dependencies cause unexpected issues. Delete yournode_modulesfolder,package-lock.json(oryarn.lock), then run:npm install npm run dev # or your project's build command
内容的提问来源于stack exchange,提问作者Corristo

