-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error: firebase.initializeApp is not a function #392
Comments
having exactly the same error - can create the instance of firebase, but can't pass it to the firebase ui component. seems like people previously had this issue but their solutions didn't apply to my case |
I didn't see these React firebase components before, but they're working for me instead of using this method |
This is an issue with firebase-js-sdk. I have encountered issues with it in 5.0.2 which worked after switching back to 5.0.1. |
I'm getting Which version on firebase are you using? ** 5.0.1 is working for with firebaseui but giving same 'credential' problem as the react-firebaseui component. |
@ee92 I was having that issue for a moment. I reinstalled firebase at 4.12.0 and now it appears to be working |
Just released v3.0.4 of react-firebaseui that now depends on the latest major versions of firebase and firebaseui. I've restricted the peer dependency of firebase to v5.0.0 and v5.0.1 because of the webpack issue. I'll change that whenever the next minor version has the fix. |
I wasn't able to reproduce the |
I had the same error with nuxt.js. config.resolve.alias['firebase/app'] = __dirname + '/node_modules/firebase/app/dist/index.cjs.js' Before adding these lines, webpack loads '~/node_modules/firebase/app/dist/index.esm.js' |
I've seen the same issue with the firebaseui widget giving the error Since I don't know what the right solution here is, but I suspect doing something like wrapping the two For the moment, I'm working around this issue by loading |
@jshcrowthe FYI. I think the issues is coming from the mixed use of both the ESM and CJS imports of the firebase library. In react projects for instance, many developers will use ESM imports: import firebase from 'firebase/app'; but, in the same project, they will import var firebase = require('firebase/app'); The issue here is that webpack will only load One possible workaround for Alternatively developers can add the following to their project's webpack config: {/* Workaround for issue https://github.com/firebase/firebaseui-web/issues/392 */},
{
test: /npm\.js$/,
loader: 'string-replace-loader',
include: path.resolve('node_modules/firebaseui/dist'),
query: {
search: 'require(\'firebase/app\');',
replace: 'require(\'firebase/app\').default;',
},
}, Other way to fix this for everyone would be to have a Not sure if there is a much better way to handle this. In webpack/webpack#6584 @sokra says both CJS and ESM should export the same API. Although it's nicer to use directly the way firebase has done it but it's true that it complicates things for webpack (it's not efficient to import the same library twice), we won't avoid mixed uses of |
Thanks for the solution, Nicolas! {
test: /npm\.js$/,
loader: 'string-replace-loader',
include: path.resolve('node_modules/firebaseui/dist'),
options: {
search: 'require(\'firebase/app\');',
replace: 'require(\'firebase/app\').default;',
},
}, |
Very cool, but CRA |
) * Using default attribute of Firebase require statement if available fixes #392 * Add typeof
@invernizzi 's webpack code worked for me. Just needed to remember to install "string-replace-loader". |
To those who got this work, was the fix placing this in webpack.config.js as so?
|
Any solution for a create-react-app project where I cannot modify the webpack config? |
If it helps others, for me, this issue was solved by removing firebase-tools from my package.json file. |
Getting same issue, Anyone got a solution for rollup here? Strange to have this problems just with a simple import. |
Turns out I had to do this instead: |
thnx, it works |
I wish I didn't have to write it like that tbh |
This works for me:
|
thanx man it works |
Thank you, it works now! |
Like a charm! Thank you. |
I'm trying to use the firebaseUI library for authentication in a react app made with create-react-app. It works great in a standard html/js app but I can't get it to work with react.
here is my simple login component:
All the firebase stuff works until I try to initialize the firebaseUI widget using
new firebaseui.auth.AuthUI(firebase.auth())
which is when it throws an error saying firebase.initializeApp is not a function. Problem seems to be stemming fromnode_modules/firebaseui/dist/npm.js:340
where initializeApp gets called.Anyone else experienced this behavior (and hopefully resolved it)?
Here are my firebase dependancies btw:
"firebase": "^5.0.2",
"firebaseui": "^3.0.0"
The text was updated successfully, but these errors were encountered: