Google云函数-类型错误无法读取属性'addQmark

时间:2018-06-27 05:57:12

标签: firebase google-cloud-platform google-cloud-firestore admin firebase-admin

有问题的错误

TypeError: Cannot read property 'addQmark' of undefined at Object.<anonymous> (/user_code/node_modules/firebase-admin/node_modules/nanomatch/lib/compilers.js:92:15) at Object.visit (/user_code/node_modules/firebase-admin/node_modules/snapdragon/lib/compiler.js:129:15) at Object.mapVisit (/user_code/node_modules/firebase-admin/node_modules/snapdragon/lib/compiler.js:143:12) at Object.compile (/user_code/node_modules/firebase-admin/node_modules/snapdragon/lib/compiler.js:168:10) at Snapdragon.compile (/user_code/node_modules/firebase-admin/node_modules/snapdragon/index.js:156:32) at /user_code/node_modules/firebase-admin/node_modules/micromatch/index.js:786:23 at memoize (/user_code/node_modules/firebase-admin/node_modules/micromatch/index.js:859:13) at Function.micromatch.compile (/user_code/node_modules/firebase-admin/node_modules/micromatch/index.js:783:10) at create (/user_code/node_modules/firebase-admin/node_modules/micromatch/index.js:686:25) at /user_code/node_modules/firebase-admin/node_modules/micromatch/index.js:695:16

相关代码:

export const schedulerTick = functions.https.onRequest((req, res) => {const dayDefinitions = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];const scheduledJobsDoc = admin.firestore().collection('System').doc('Scheduled Jobs');const jobBufferSeconds = 5 * 60;const datestamp = new Date();return scheduledJobsDoc.getCollections().then(jobTypeCollections =>[].concat.apply([], [jobTypeCollections.map(job => job.where('Completed', '==', false).where('Periodic', '==', false)//.orderBy('Trigger')//.startAt(datestamp)//.endAt(new Date(Date.now() + 1000 * jobBufferSeconds)).get().then(onetimeJobs => onetimeJobs.docs.map(doc => {return {data: doc.data(), ref: doc.ref};})).then(MITM).catch(e => console.warn('ERROR: ', e))),jobTypeCollections.map(job => job.where('Periodic', '==', true).where(`Recurrence.${dayDefinitions[new Date().getDay()]}`, '==', true)//.orderBy('Trigger')//.startAt((new Date(Date.now() - 1000 * jobBufferSeconds)))//.endAt(new Date(Date.now() + 1000 * jobBufferSeconds)).get().then(onetimeJobs => onetimeJobs.docs.map(doc => {return {data: doc.data(), ref: doc.ref};})).then(MITM).catch(e => console.warn('ERROR: ', e)))])).then(docs => Promise.all(docs)).then(resolvedDocs => [].concat.apply([], resolvedDocs) as JobDB[]).then(doJobs).then(docs => res.status(200).send({date:datestamp, startAt: (new Date(Date.now() - 1000 * jobBufferSeconds)), endAt: new Date(Date.now() + 1000 * jobBufferSeconds), docs: docs})).catch(e => { console.warn('ERROR:', e); res.status(500).send(e) });});const doJobs = ((jobs: JobDB[]) => {const results = jobs.map(job => {// Detect job typeswitch (job.data.Action) {case 'Test': {console.warn('A SCHEDULED TEST RAN');return Promise.resolve();}case 'Enable': {console.warn('A SCHEDULED ENABLE', job.data.Target.path);return job.data.Target.set({ Enabled: true, Archived: false } , { merge: true });}case 'Archive': {console.warn('A SCHEDULED ARCHIVE');return job.data.Target.set({ Enabled: false, Archived: true } , { merge: true });}default: {console.warn('INVALID JOB ACTION');return Promise.resolve();}}}) as Promise<void>[];return Promise.all(results).then(() => {return jobs.map(x => { // Mark job as completedx.ref.set({Completed: true}, {merge: true});return x.data;});}).catch(e => console.warn('Caught an error: ', e))});const MITM = (param) => {console.log(param);return param;}

1 个答案:

答案 0 :(得分:0)

最好的做法似乎是安装此版本的nanomatch:

npm install nanomatch@1.2.9 -S

感谢@DazWilkin