如何解决部署错误的云功能-Firebase部署
在执行firebase deploy命令时返回错误。我尝试了一些配置选项,但没有用。
错误Firebase部署
=== 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,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
我的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-原始状态,不变。
{
"compilerOptions": {
"module": "commonjs","noImplicitReturns": true,"noUnusedLocals": true,"outDir": "lib","sourceMap": true,"strict": true,"target": "es2017"
},"compileOnSave": true,"include": [
"src"
],}
package.json-原始状态,不变。
{
"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
}
我更改了一些打字稿设置,但是没有用。我将所有内容恢复为原始状态。
解决方法
显然,发出命令firebase init解决了这种情况。