[英]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.