部署时发生意外错误

时间:2019-05-26 14:45:14

标签: javascript node.js firebase google-cloud-functions firebase-cli

当我尝试命令

时,我正尝试按照此视频https://www.youtube.com/watch?v=NybmemQxdts&list=PLB6lc7nQ1n4h5tzT3tu_YSy9VNrVUR_4W&index=8的从一台设备向另一台设备发送消息
firebase deploy --only functions

向我展示

=== Deploying to 'firemessages-8a812'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

Error: An unexpected error has occurred.

我尝试通过此命令更新Firebase工具

npm install -g firebase-tools

但仍然出现相同的错误,这是我的index.js

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp();

exports.notifyNewMessage = functions.firestore
    .document('chatChannels/{channel}/messages/{message}')
    .onCreate((docSnapshot, context) => {
        const message = docSnapshot.data();
        const recipientId = message['recipientId'];
        const senderName = message['senderName'];
    return admin.firestore().doc('users/' + recipientId).get().then(userDoc => {
        const registrationTokens = userDoc.get('registrationTokens')
        const notificationBody = (message['type'] === "TEXT") ? message['text'] : "You received a new image message."
        const payload = {
            notification:{
                title: senderName + " sent you a message.",
                body: notificationBody,
                clickAction: "ChatActivity"
            },
            data: {         
                USER_NAME: senderName,
                USER_ID: message['senderId']
                  }
            };

        return admin.messaging().sendToDevice(registrationTokens, payload).then( response => {
                const stillRegisteredTokens = registrationTokens

                response.results.forEach((result, index) => {
                    const error = result.error
                    if (error){
                        const failedRegistrationToken = registrationTokens[index]
                        console.error('blah', failedRegistrationToken, error)
                        if(error.code === 'messaging/invalid-registration-token'
                            || error.code === 'messaging/registration-token-not-registered'){

                            const failedIndex = stillRegisteredTokens.indexOf(failedRegistrationToken)
                            if(failedIndex > -1){
                                stillRegisteredTokens.splice(failedIndex, 1)
                            }
                        }
                    }
            })

            return admin.firestore().doc("users" + recipientId).update({
                registrationTokens: stillRegisteredTokens
        })
    })
})

})

这是命令firebase deploy--debug

的结果
[2019-05-26T15:24:58.929Z] ----------------------------------------------------------------------
[2019-05-26T15:24:58.932Z] Command:       /usr/bin/node /usr/local/bin/firebase deploy --debug
[2019-05-26T15:24:58.933Z] CLI Version:   6.4.0
[2019-05-26T15:24:58.933Z] Platform:      linux
[2019-05-26T15:24:58.933Z] Node Version:  v8.0.0
[2019-05-26T15:24:58.933Z] Time:          Sun May 26 2019 17:24:58 GMT+0200 (EET)
[2019-05-26T15:24:58.933Z] ----------------------------------------------------------------------

[2019-05-26T15:24:58.940Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2019-05-26T15:24:58.940Z] > authorizing via signed-in user
[2019-05-26T15:24:58.940Z] [iam] checking project firemessages-8a812 for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get","firebasehosting.sites.update"]
[2019-05-26T15:24:58.942Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[2019-05-26T15:24:58.942Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token  
 <request body omitted>
[2019-05-26T15:24:59.366Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=utf-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:24:59 GMT, server=scaffolding on HTTPServer2, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-05-26T15:24:59.438Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/firemessages-8a812:testIamPermissions  
 permissions=[cloudfunctions.functions.create, cloudfunctions.functions.delete, cloudfunctions.functions.get, cloudfunctions.functions.list, cloudfunctions.functions.update, cloudfunctions.operations.get, firebase.projects.get, firebasehosting.sites.update]
[2019-05-26T15:25:00.552Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:00 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, server-timing=gfet4t7; dur=747, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-05-26T15:25:00.554Z] >>> HTTP REQUEST GET https://firebase.googleapis.com/v1beta1/projects/firemessages-8a812  

[2019-05-26T15:25:01.161Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:01 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked

=== Deploying to 'firemessages-8a812'...

i  deploying functions, hosting
[2019-05-26T15:25:02.915Z] > [functions] package.json contents: {
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase-admin": "~7.0.0",
    "firebase-functions": "^2.2.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1"
  },
  "private": true
}
i  functions: ensuring necessary APIs are enabled...
[2019-05-26T15:25:02.916Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/cloudfunctions.googleapis.com/projectSettings/firemessages-8a812?view=CONSUMER_VIEW  

[2019-05-26T15:25:02.916Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/runtimeconfig.googleapis.com/projectSettings/firemessages-8a812?view=CONSUMER_VIEW  

[2019-05-26T15:25:04.440Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:04 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-05-26T15:25:04.623Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:04 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
✔  functions: all necessary APIs are enabled
[2019-05-26T15:25:04.625Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/firemessages-8a812  

[2019-05-26T15:25:05.669Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:05 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, server-timing=gfet4t7; dur=750, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-05-26T15:25:05.671Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/1092037542148:getServerAppConfig  

[2019-05-26T15:25:06.231Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:06 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-05-26T15:25:06.236Z] >>> HTTP REQUEST POST https://firebasehosting.googleapis.com/v1beta1/sites/firemessages-8a812/versions  
 headers=[glob=**/*.@(js|html), Cache-Control=max-age=0], deployment-tool=cli-firebase
[2019-05-26T15:25:08.432Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:08 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
i  functions: preparing functions directory for uploading...
[2019-05-26T15:25:08.435Z] >>> HTTP REQUEST GET https://runtimeconfig.googleapis.com/v1beta1/projects/firemessages-8a812/configs  

[2019-05-26T15:25:09.965Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 26 May 2019 15:25:09 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-05-26T15:25:10.095Z] TypeError: Cannot read property 'pipesCount' of undefined
    at module.exports.Readable.pipe (_stream_readable.js:545:16)
    at module.exports.ZipArchiveOutputStream._smartStream (/usr/local/lib/node_modules/firebase-tools/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:184:11)
    at module.exports.ZipArchiveOutputStream._appendBuffer (/usr/local/lib/node_modules/firebase-tools/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:82:10)
    at module.exports.ArchiveOutputStream.entry (/usr/local/lib/node_modules/firebase-tools/node_modules/compress-commons/lib/archivers/archive-output-stream.js:86:10)
    at module.exports.ZipStream.entry (/usr/local/lib/node_modules/firebase-tools/node_modules/zip-stream/index.js:157:49)
    at Zip.append (/usr/local/lib/node_modules/firebase-tools/node_modules/archiver/lib/plugins/zip.js:54:15)
    at Archiver._moduleAppend (/usr/local/lib/node_modules/firebase-tools/node_modules/archiver/lib/core.js:179:16)
    at Archiver._onQueueTask (/usr/local/lib/node_modules/firebase-tools/node_modules/archiver/lib/core.js:400:8)
    at /usr/local/lib/node_modules/firebase-tools/node_modules/async/dist/async.js:4096:9
    at Object.process (/usr/local/lib/node_modules/firebase-tools/node_modules/async/dist/async.js:2344:17)

Error: An unexpected error has occurred.

0 个答案:

没有答案