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

从firebase.js导入auth失败:模块路径错误求助

解决Firebase导入时的"Module not found"错误

你遇到的错误根源在firebase.js里的导入路径写错了:

看你的firebase.js代码里这一行:

import { getAuth } from "/firebase/auth";

开头的斜杠/会让打包工具把它当成项目根目录之外的绝对路径去查找,自然找不到正确的Firebase模块。正确的写法应该是去掉开头的斜杠,直接从npm安装的Firebase包导入:

import { getAuth } from "firebase/auth";

修正后的完整firebase.js代码如下:

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getStorage } from "firebase/storage";

const firebaseConfig = {
  apiKey: "<API_KEY>",
  authDomain: "chateapp.com",
  projectId: "ch715c",
  storageBucket: "chaom",
  messagingSenderId: "4960541",
  appId: "<APP_ID>"
};

// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const auth = getAuth();
export const storage = getStorage();

另外确认Register.jsx里的导入import { auth, storage } from '../firebase'是正确的——Register在src/pages目录下,firebase.js在src根目录,这个相对路径没问题。

改完之后重启开发服务器,应该就能正常运行了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 08:25:55