firestore-codelab-extended-swift
                                
                                 firestore-codelab-extended-swift copied to clipboard
                                
                                    firestore-codelab-extended-swift copied to clipboard
                            
                            
                            
                        can't get firebase to properly deploy in Terminal command line
hello,
i am running a mac and working on the iOS version of this tutorial. i cannot seem to get the 'firebase deploy' command line to run properly. i have been working to on this for the better part of a day to try and fix it, and i believe the error is not on my end. i could be wrong of course.
here is the Terminal error output:
<MY_DIRECTORY_WITH_NO_SPACES_IN_THE_PATH>src (master) $ firebase deploy
=== Deploying to 'friendly-eats-tutorial'...
i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run build
functions@ build /Users/kellyjohnson/Dropbox/Guata_Dev/DevMountain_iOS/firestore-codelab-extended-swift/functions tsc
src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read.
1 import * as functions from 'firebase-functions';
Found 1 error.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/kellyjohnson/.npm/_logs/2019-05-30T02_20_12_145Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
any help would be greatly appreciated.
cheers
Looks like there's a TypeScript error in your code. Can you share your code?
sure thing! thank you!
as far as i can tell, and who knows maybe i missed something, this is copied directly from the codelabs tutorial page.
here is the code from the index.ts file of my local project...
//  Copyright (c) 2018 Google Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
// TODO(DEVELOPER): Import the Cloud Functions for Firebase and the Firebase Admin modules here.
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
type Firestore = admin.firestore.Firestore;
const app = admin.initializeApp();
export const computeAverageReview = functions.firestore
    .document('reviews/{reviewID}').onWrite((change, context) => {
        // get the data from the write event
        const eventData = change.after.data();
        // get the previous value, if it exists
        const prev = change.before;
        const rating = eventData.rating;
        let previousValue
        if (prev.exists) {
            previousValue = prev.data;
            const prevRating = previousValue.rating;
            if (rating == prevRating) {
                console.log("not a new rating.");
                return null;
            }
        }
        // get the restaurant ID
        const restaurantID = eventData.restaurantID;
        // get the reference to the root of the firebase DB
        const db = app.firestore();
        // if a previous value exists, then it needs to be replaced when computing an average....
        // otherwise, add the new rating
        if (prev.exists) {
            const difference = previousValue.rating - rating
            return updateAverage(db, restaurantID, difference, true);
        } else {
            return updateAverage(db, restaurantID, rating, false);
        }
    });
async function updateAverage(db: Firestore, restaurantID: string, newRating: number, prev: boolean) {
    const updateDB = db.collection('restaurants').doc(restaurantID);
    const restaurantDoc = await updateDB.get();
    if (!restaurantDoc.exists) {
        console.log("Document does not exist!");
        return null;
    }
    const oldRating = restaurantDoc.data().averageRating;
    const oldNumReviews = restaurantDoc.data().reviewCount;
    let newNumReviews = oldNumReviews+1;
    let newAvgRating = ((oldRating*oldNumReviews)+newRating)/newNumReviews;
    // no need to increase review numbers if not a new review
    // subtract the difference made by the review
    if (prev) {
        newNumReviews = oldNumReviews;
        newAvgRating = ((oldRating*oldNumReviews)-newRating)/oldNumReviews;
    }
    await updateDB.update({averageRating: newAvgRating, reviewCount: newNumReviews});
    console.log("average updated");
    return null;
}
^^^ that's everything the index.ts file contains thus far from soup to nuts. not sure why it's not all being presented as a code snippet. sorry for any confusion that way.
Looks like this error was added in TypeScript 2.6. What version of TypeScript (or tslint) are you using?
You can disable the error as described here.
typescript version 3.5.1 just did a fresh install
tslint version 5.17.0
kellyjohnson@GuataDev-MacBook-Pro functions (master) $ firebase deploy
=== Deploying to 'friendly-eats-tutorial'...
i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run build
functions@ build /my_path_with_no_spaces/firestore-codelab-extended-swift/functions tsc
src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read.
1 import * as functions from 'firebase-functions';
Found 1 error.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /my_path_with_no_spaces/.npm/_logs/2019-05-30T20_35_51_852Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
^^^ i just did fresh installs for both typescript and TSLint tried the deploy again and got the above error output via Terminal
i made the change in the tsconfig.json file for the fix you included above and it deployed! thank you!
i really appreciate your help!!! super responsive and knowledgable. 👍 😃 👍
No problem, I'll remove the flag from the tsconfig in the codelab since the codelab is focusing on Swift and we don't want people to get hung up on unused variable errors in TS.
Thanks for reporting this issue!
it was my pleasure to be of any help! i am just super humbled by the support you gave me! the developer community spirit of collaboration is a beautiful thing to behold! cheers to you and your whole team!
Is this solved? I've just set up a new project using WebStorm according to the guides that the firebase and angular assistants gave me, so basically an empty boilerplate project, and the error persists.
Thanks. It can be "solved" by removing the comments in functions/src/index.ts.
IMHO this should however work out of the box. A raw, unmodified boilerplate project with the default options should always work. It should also work with whatever possible combinations of options one might choose during initialization.
This should be fixed in master now. Please let me know if you run into any more issues.
@HWiese1980 big thanks Works fine on March 2020 ;)
Just did the tutorial on installing firebase-functions also got this error. Removing the comments worked for me. I back-up @HWiese1980
i made the change in the tsconfig.json file for the fix you included above and it deployed! thank you!
what were those changes plz help me