I have a problem with firestore. I want to read some data from firebase but I can't import collection from firebase Attempted import error: 'collection' is not exported from 'firebase/firestore/'. I read some articles that said this problem is related to v9 SDK.
You have to import the Firebase SDKs correctly. The issue is in the first line where you are importing from "firebase" directly which is not the ideal method and as per my understanding, the import calls/methods are not in sync with the version changes. Be sure to read the documentation on using Firebase with module bundlers
Starting with Firebase v8.0.0, you have to import Firebase SDKs as per the documentation where it is mentioned that there was a breaking change in version 8.0 where
browser fields in package.json files now point to ESM bundles instead
of CJS bundles. Users who are using ESM imports must now use the
default import instead of a namespace import
Before 8.0.0
import * as firebase from 'firebase/app'
After 8.0.0
import firebase from 'firebase/app'
Code that uses require('firebase/app') or require('firebase') will still work, but you should change these require calls to require('firebase/app').default or require('firebase').default
Change your code as shown below :
import firebase from "firebase/app"
import { getFirestore } from "firebase/firestore";
import { collection, addDoc, getDocs } from "firebase/firestore";
import "firebase/auth"
const auth = firebase.auth()
This should work for you. If not, then probably you have updated your SDK version from 8 to 9 and with version 9 things changed a bit for importing firebase, but there is no need to downgrade to a previous version, there is a "compatibility" option so can use the /compat folder in your imports, like this
import firebase from 'firebase/compat/app';
From the Firebase documentation:
In order to keep your code functioning after updating your dependency
from v8 to v9 beta, change your import statements to use the "compat"
version of each import as shown below (v9 compat packages are API
compatible with v8 code) :
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
That error message means there is no such export "collection" from the module "firebase/firestore/". So the error is on the second line when you are trying to import "collection".
In the docs there is no trailing "/" in "firebase/firestore". Try removing that trailing "/" and try again.
I suggest you follow this guide on setting up firestore
Related
I was making a linkedin clone following Clever programmer's video. In their video they Imported firebase using import firebase from "firebase"
But I can't import firebase from firebase. I can only import folders in firebase eg: auth, app
Also I have the Import cost extension installed. It detects firebase/auth, firebase/firestore
kind of imports but it doesn't detect import firebase from firebase
How can I solve this problem. Any help will be much appreciated. I'm stuck for 5 days now.
Trying to configure pod retention value for Jenkins Kubernetes plugin using
groovy script.
kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.Podretention.Never())
method is failing to configure with below error :
Invalid value provided in main configuration No signature of method: static
org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never()
is applicable for argument types: () values: []
tried configuring by using different values for the method:
kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.Never)
Error using the above value as well.
Please someone help me with this as I was struck with this from quite along.
Below is the code:
import java.util.logging.Logger
import hudson.*
import hudson.model.*
import java.io.PrintWriter
import java.io.StringWriter
import jenkins.*
import jenkins.install.InstallState
import jenkins.model.*
import jenkins.util.xml.*
import javax.xml.xpath.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import org.jenkinsci.plugins.plaincredentials.impl.*
import org.jenkinsci.plugins.docker.commons.credentials.*
import org.csanchez.jenkins.plugins.kubernetes.*
import org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention
KubernetesCloud kubernetes = new KubernetesCloud('test')
kubernetes.setServerUrl('http://test_url')
kubernetes.setMaxRequestsPerHostStr(20)
kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never())
kubernetes.setWaitForPodSec(90)
// documentation reference
https://javadoc.jenkins.io/plugin/kubernetes/
// Method used
setPodRetention(PodRetention podRetention)
Set the global pod retention policy for the plugin.
Can some let me know how to set the pod retention value with values never
, always etc.
You are missing new keyword that is required to create an object. The line
kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never())
Should be
kubernetes.setPodRetention(new org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never())
To configure global pod retention policy go to https://jenkins_url/configure (or https://jenkins_url/configureClouds in latest lts version of jenkins) and update "Pod Retention" configuration grouped under Kubernetes Cloud
I am trying to use firebase massaging in my SSR app which is created using https://github.com/jaredpalmer/razzle with-react-router-3. I am already using firebase which works great including hosting. But started throwing an error when I started adding messaging in the app.
My entry point looks like,
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import 'firebase/storage';
import 'firebase/firestore';
import 'firebase/messaging';
import FirebaseConfig from 'config/firebase-config.json';
if (!firebase.apps.length) {
firebase.initializeApp(FirebaseConfig);
}
const messaging = firebase.messaging();
I am getting the bellow error when I start the server with razzle start
/Users/subkundu/Desktop/Work/Projects/React/ownerstown/node_modules/#firebase/messaging/index.ts:75
if (self && 'ServiceWorkerGlobalScope' in self) {
^
ReferenceError: self is not defined
How do I fix it? Any lead will be amazing. Thanks. :)
I believe that you have to provide a check to see if the window is available.
let Messaging;
if (YOUR_CHECK_HERE) {
Messaging = firebase.messaging();
}
// Then you can use "Messaging"
I'm not familiar with razzle. Accessing the window varies depending on Server Side Rendering (SSR) frameworks. I got the idea from this post. When I ran into this problem with nuxt.js I was able to check for the window with this process.browser. Hope this helps!
I have referred this documentation to add google-signin in my react native app, followed all the steps mentioned but could not get the result as specified in the documentation. I have imported the following statement
import { GoogleSignin, GoogleSigninButton, statusCodes } from 'react-native-google-signin';
But Whenever I add this statement in my login file it gives me following error.
i think you need make some changed in your file path shown in error message
F:\ReactProjects\SearchApp\node_modules\react-native-google-signin\src\GoogleSignin.android.js
make sure you import following two lines correctly
import React, { Component } from 'react';
import PropTypes from 'prop-types';
install this and your problem goes away "npm install --save prop-types"
In the angular firebase, I came across following two things:
import { AngularFireDatabase } from 'angularfire2/database';
import firebase from 'firebase';
If both can be used for interacting with the database, what is the difference between them?
The first line imports the AngularFire2 library.
The second line imports the Firebase JavaScript SDK, which is what AngularFire uses under the hood.