简体   繁体   English

未找到模块:错误:您尝试导入项目 src/ 目录之外的 /firebase/app

[英]Module not found: Error: You attempted to import /firebase/app which falls outside of the project src/ directory

I had it working on a different project before and going off that as a reference but I still get this same error.我之前曾在另一个项目上工作过,并将其作为参考,但我仍然遇到同样的错误。 My utils folder is inside the src directory.我的 utils 文件夹位于 src 目录中。 Can not seem to find out whats going on.似乎无法找出发生了什么。 Directory image目录图片

import { initializeApp } from '/firebase/app'
import { getAuth, signInWithRedirect, signInWithPopUp, GoogleAuthProvider } from '/firebase/auth'


// Your web app's Firebase configuration
const firebaseConfig = {
    // api keys //
};

// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig);


const provider = new GoogleAuthProvider()
provider.setCustomParameters({
    prompt: 'select_account'
})

export const auth = getAuth()
export const signInWithGooglePopUp = () => signInWithPopUp(auth, provider)


// Sign-in component //

import { signInWithGooglePopUp } from "../../utils/firebase/firebase.utils";

const SignIn = () => {
  const logGoogleUser = async () => {
    const response = await signInWithGooglePopUp();
  };

  return (
    <div>
      <h1>Sign In</h1>
      <button onClick={logGoogleUser}> Sign in with Google</button>
    </div>
  );
};

export default SignIn;

You didn't say what error you're getting, but presumably it can't find firebase.utils.js你没有说你得到了什么错误,但大概是找不到 firebase.utils.js

My first guess would be your relative path is not correct from where node is running: ../../我的第一个猜测是您的相对路径从节点运行的位置不正确:../../

Did you try removing the relative paths?您是否尝试删除相对路径?

import { initializeApp } from '/firebase/app'
import { getAuth, signInWithRedirect, signInWithPopUp, GoogleAuthProvider 
} from '/firebase/auth'


// Your web app's Firebase configuration
const firebaseConfig = {
    // api keys //
};

// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig);

const provider = new GoogleAuthProvider()
provider.setCustomParameters({
    prompt: 'select_account'
})

export const auth = getAuth()
export const signInWithGooglePopUp = () => signInWithPopUp(auth, 
provider)


// Sign-in component //

import { signInWithGooglePopUp } from 
"utils/firebase/firebase.utils";

const SignIn = () => {
const logGoogleUser = async () => {
    const response = await signInWithGooglePopUp();
  };

  return (
    <div>
      <h1>Sign In</h1>
      <button onClick={logGoogleUser}> Sign in with Google</button>
    </div>
  );
};

export default SignIn;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “您试图通过调用 firebase.app() 来使用 Android 项目中未安装的 firebase 模块。” - "You attempted to use a firebase module that's not installed on your Android project by calling firebase.app()." 您试图通过调用 firebase.storage() 来使用未安装在 android 项目上的 firebase 模块 - You attempted to use a firebase module that's not installed on your android project by calling firebase.storage() 升级到 Firebase JS 8.0.0:尝试导入错误:“app”未从“firebase/app”导出(导入为“firebase”) - Upgrade to Firebase JS 8.0.0: Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase') 尝试导入错误:“firebase/app”不包含默认导出(导入为“firebase”) - Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase') 从 Angular Ionic 项目中的“@firebase/app”导入 { Firebase } 时出错 - Error with import { Firebase } from '@firebase/app' in Angular Ionic project 不能在模块外使用 import 语句,TypeScript NodeJS Firebase Functions 项目 - Cannot use import statement outside a module, TypeScript NodeJS Firebase Functions project 错误 in./src/firebase.config.js 6:0-53 未找到模块:错误:Package 路径。/getFirestore 未从 package 导出 - ERROR in ./src/firebase.config.js 6:0-53 Module not found: Error: Package path ./getFirestore is not exported from package NEXT AUTH + Firebase 无法在模块外导入语句 - NEXT AUTH + Firebase Cannot import statement outside a module 未找到模块:错误:无法解析“./Firebase” - Module not found: Error: Can't resolve './Firebase' 如何导入 firebase 应用程序作为浏览器模块导入? - How can I import firebase app as browser module import?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM