firebase / firebase/snippets-web
Error on firebase require in node JS
- Dominant language
- JavaScript
- Stars
- 802
- Forks
- 285
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to use firebase auth in the backend for authentification i tried to follow the firebase documentation to import these functions which does not work for nodeJS
```
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
Signed in
const user = userCredential.user;
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message; });
```
i tried to change the into a const ... = require() instead of an import
but now i'm getting this error
`FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).`
if i use the old version with firebase 8 requiring firebase i'm getting this error,
`[Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" - Firebase](https://stackoverflow.com/questions/69200493/error-err-package-path-not-exported-no-exports-firebase)`
i'm trying to create a user in a express app endpoint:
```
app.post('/signup', (req, res) => {
const newUser = {
email: req.body.email,
password: req.body.password,
confirmPassword: req.body.confirmPassword,
handle: req.body.handle,
}
createUserWithEmailAndPassword(auth, newUser.email, newUser.password)
.then(data => {
return res.status(201).json({ message: `user${data.user.uid} signed up succesfully` })
})
.catch(err => {
console.error(err)
return res.status(500).json({ error: err.code })
})
})
```
How can i solve my problem ??
Contributor guide
Assessment
This issue has not been assessed yet.