'Deploy error Cloud Functions - Firebase Deploy

Error returning when executing the firebase deploy command. I tried some configuration options, but none worked.

Error Firebase Deploy

=== Deploying to '###'...

i  deploying functions
Running command: npm --prefix "%RESOURCE_DIR%" run lint

> functions@ lint C:\usCloud\functions
> tslint --project tsconfig.json


WARNING: C:/usCloud/functions/src/index.ts:13:10 - bodyParser is deprecated.
WARNING: C:/usCloud/functions/src/index.ts:14:10 - bodyParser is deprecated.

Running command: npm --prefix "%RESOURCE_DIR%" run build

> functions@ build C:\usCloud\functions
> tsc

node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, WriteBatch, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, FieldValue, FieldPath, Timestamp, v1beta1, v1, OK, CANCELLED, UNKNOWN, INVALID_ARGUMENT, DEADLINE_EXCEEDED, NOT_FOUND, ALREADY_EXISTS, PERMISSION_DENIED, RESOURCE_EXHAUSTED, FAILED_PRECONDITION, ABORTED, OUT_OF_RANGE, UNIMPLEMENTED, INTERNAL, UNAVAILABLE, DATA_LOSS, UNAUTHENTICATED, FirebaseFirestore

23 declare namespace FirebaseFirestore {
   ~~~~~~~

  node_modules/firebase-functions-helper/node_modules/@google-cloud/firestore/types/firestore.d.ts:25:1
    25 declare namespace FirebaseFirestore {
       ~~~~~~~
    Conflicts are in this file.

node_modules/firebase-functions-helper/node_modules/@google-cloud/firestore/types/firestore.d.ts:25:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, WriteBatch, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, FieldValue, FieldPath, Timestamp, v1beta1, v1, OK, CANCELLED, UNKNOWN, INVALID_ARGUMENT, DEADLINE_EXCEEDED, NOT_FOUND, ALREADY_EXISTS, PERMISSION_DENIED, RESOURCE_EXHAUSTED, FAILED_PRECONDITION, ABORTED, OUT_OF_RANGE, UNIMPLEMENTED, INTERNAL, UNAVAILABLE, DATA_LOSS, UNAUTHENTICATED, FirebaseFirestore

25 declare namespace FirebaseFirestore {
   ~~~~~~~

  node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
    23 declare namespace FirebaseFirestore {
       ~~~~~~~
    Conflicts are in this file.

node_modules/firebase-functions-helper/node_modules/@google-cloud/firestore/types/firestore.d.ts:168:5 - error TS2374: Duplicate string index signature.

168     [key: string]: any; // Accept other properties, such as GRPC settings.
        ~~~~~~~~~~~~~~~~~~~


Found 3 errors.

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!     C:\Users\##\AppData\Roaming\npm-cache\_logs\2020-08-26T16_49_58_562Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code2

My index.ts

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as firebaseHelper from 'firebase-functions-helper/dist';
import * as express from 'express';
import * as bodyParser from 'body-parser';

admin.initializeApp(functions.config().firebase);
const db = admin.firestore;

const app = express();
const main = express();

main.use(bodyParser.json());
main.use(bodyParser.urlencoded({extended: false}));
main.use('/api/v1', app);

const trackerCollection = 'tracker';
export const webApi = functions.https.onRequest(main);

app.patch('/tracker/:tid', async(req, res) => {
    try {
        await firebaseHelper.firestore.updateDocument(db, trackerCollection, req.params.tid, req.body);
        res.status(200).send('Update Success');
    } catch (error) {
        res.status(204).send('Patch Error');
    }
})

tsconfig.json - Original condition, unchanged.

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
}

package.json - Original condition, unchanged.

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "main": "lib/index.js",
  "dependencies": {
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "firebase-admin": "^8.10.0",
    "firebase-functions": "^3.6.1",
    "firebase-functions-helper": "^0.8.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0",
    "tslint": "^5.12.0",
    "typescript": "^3.9.7"
  },
  "private": true
}

I changed some typescript settings, but it didn't work. I returned everything to its original state.



Solution 1:[1]

Apparently, issuing the command firebase init resolved this scenario.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrTech