You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SvelteKit集成Firebase Auth遇Vite依赖路径冲突错误求助

解决SvelteKit中Firebase Auth导入导致的"Two output files share the same path"错误

在SvelteKit项目中,执行import { createUserWithEmailAndPassword } from "firebase/auth";这类Firebase Auth导入语句时,触发以下错误:

Two output files share the same path but have different contents: node_modules.vite\deps_temp_0b51b981\firebase_auth.js

已排查确认无重复导入、大小写问题无异常,以下是几个可行的解决思路:

1. 清理Vite依赖缓存

这是Vite打包时依赖缓存冲突的典型问题,直接删除Vite的缓存目录即可:

  • 手动删除项目根目录下的node_modules/.vite文件夹
  • 重启开发服务器

命令行执行(Windows用户替换为rmdir /s /q node_modules\.vite):

rm -rf node_modules/.vite
npm run dev

2. 统一Firebase依赖版本

确保所有Firebase相关包的版本完全一致,版本不匹配会导致Vite打包时生成冲突的依赖文件。打开package.json检查,比如:

{
  "dependencies": {
    "firebase": "^10.7.1",
    "firebase/app": "^10.7.1",
    "firebase/auth": "^10.7.1",
    "firebase/firestore/lite": "^10.7.1"
  }
}

如果版本不一致,重新安装统一版本:

npm install firebase@latest
# 若分开安装子包,执行:
npm install firebase/app@latest firebase/auth@latest firebase/firestore/lite@latest

3. 修正Firebase初始化代码的遗漏

你提供的firebase.js中直接使用了getAuth但未导入该方法,这会导致运行时错误,先补上导入:

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth"; // 补上这行
import { collection, doc, getFirestore } from "firebase/firestore/lite";

const firebaseConfig = { /* 你的配置 */ };

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
const userDoc = (userId) => doc(db, "users", userId);

export { auth, userDoc };

4. 更新Vite和SvelteKit版本

旧版本的Vite或SvelteKit可能存在依赖打包的bug,尝试更新到最新稳定版:

npm install @sveltejs/kit@latest vite@latest

内容的提问来源于stack exchange,提问作者Jardo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 18:22:38