问题
I'm trying to connect to google firestore and for some reason my process.env.FIREBASE_PROJECT_ID
keeps spitting out the error:
@firebase/firestore: Firestore (7.17.1): Connection GRPC stream error. Code: 3 Message: 3 INVALID_ARGUMENT: Project id 'name-of-project', is malformed: it either contains invalid characters or is too long. Look at https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects for instructions in how to get a project's id.
[2020-08-04T23:53:51.550Z] @firebase/firestore: Firestore (7.17.1): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=invalid-argument]: 3 INVALID_ARGUMENT: Project id 'name-of-project', is malformed: it either contains invalid characters or is too long. Look at https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects for instructions in how to get a project's id.
When I paste the project ID directly in, it works and connects. But when I try to use the process.env solution for whatever reason it doesnt accept it despite the fact that it's literally returning the correct project id that I am otherwise pasting in directly in the successful runs.
import * as firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/storage';
import 'firebase/analytics';
require('dotenv').config();
const config = {
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.FIREBASE_DATABASE_URL,
projectId: process.env.FIREBASE_PROJECT_ID,
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.FIREBASE_APP_ID,
measurementId: process.env.FIREBASE_MEASUREMENT_ID,
};
// Initialize Firebase
try {
firebase.initializeApp(config);
} catch (err) {
// we skip the "already exists" message which is
// not an actual error when we're hot-reloading
if (!/already exists/.test(err.message)) {
console.error('Firebase initialization error', err.stack);
}
}
// const firebaseAnalytics = firebase.analytics();
const firebaseStorage = firebase.storage();
const firebaseFirestore = firebase.firestore();
export { firebaseStorage, firebaseFirestore };
I don't know why it's doing this. I've never had this issue before. Any thoughts?
来源:https://stackoverflow.com/questions/63256611/getting-the-respsonse-invalid-argument-project-id-x-is-malformed