From ee0552f837cfdeeb212352d4987f502e3f2aaf1e Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Jul 2026 15:05:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20=E7=A7=BB=E9=99=A4=20element-p?= =?UTF-8?q?lus=20alias=20=E9=98=B2=E6=AD=A2=20CSS=20=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题原因: - 上次提交在 vite.config.js resolve.alias 中将 element-plus 直接映射到 es/index.mjs 文件路径 - 这导致 import 'element-plus/dist/index.css' 时, Vite 拼接路径为 es/index.mjs/dist/index.css,文件不存在 - 报错: Failed to resolve import 'element-plus/dist/index.css' 解决方案: - 移除 element-plus 的 resolve.alias 映射 - 包名保留为包名,Vite 的 node_modules 解析机制可正确处理 element-plus 的 JS 入口和 CSS 路径 - start.sh 已有清缓存+自动重试机制兜底 --- frontend/vite.config.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 75ea43c..34ad7c7 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,5 +1,4 @@ import { fileURLToPath, URL } from 'node:url' -import path from 'node:path' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' @@ -9,11 +8,7 @@ export default defineConfig({ plugins: [vue()], resolve: { alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)), - // 兜底:若 element-plus exports 解析失败则走 fallback - 'element-plus': path.resolve( - fileURLToPath(new URL('node_modules/element-plus/es/index.mjs', import.meta.url)) - ) + '@': fileURLToPath(new URL('./src', import.meta.url)) } }, server: {