错误:在 Firebase 中部署期间无法成功分析函数代码库

JUA*_*DAD 5 javascript firebase google-cloud-functions

我在部署 Firebase 函数期间遇到错误。我收到的错误消息是:

\n

"Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error."

\n

我已经检查了我的代码并确保没有语法错误。但是,错误仍然存​​在。我还检查了必要的 API 要求并且它们已启用。

\n

对于如何解决此问题的任何见解或建议,我将不胜感激。请在下面找到相关的代码片段:

\n
\nexport const readTarjeta = functions.storage.object().onFinalize(async (object) => {\n    const imageBucket = `gs://${object.bucket}/${object.name}`;\n    const client = new vision.ImageAnnotatorClient();\n\n    const [textDetection] = await client.textDetection(imageBucket);\n    const [annotation] = textDetection.textAnnotations;\n    const text = annotation ? annotation.description : "";\n    logger.log(text);\n\n   const re = /(.*)\\//;\n   const uid = re.exec(object.name)[1];\n\n  const regexArray = [\n    // /(?<=PROPIETARIO?)\\s*(.*)\\n/,\n    /\\bJ[a-zA-Z0-9]{6}\\b/gm,\n    /(?<=MODELO)\\s*(.*)\\n/,\n    /[a-zA-Z0-9]{17}$\\n/gm,\n];\n\nlet regExpSalto = /propietario:\\s*\\n/i;\n\n let propietario;\n let placasJ;\n let marcaJ;\n let anio;\n let modeloJ;\n let motorJ;\n let nivJ;\n \n    if(regExpSalto.test(text)){\n        let regExpBajo = /propietario:\\s*\\n\\s*((\\w+\\s){3,4})\\s+/i;\n        if(regExpBajo.test(text)){\n            let matches2 = text.match(regExpBajo);\n            if(matches2){\n                  propietario = matches2[1];\n            }\n        }else{\n\n            let a = "Propietario:\\\\s+"\n            let b = "(( +\\\\w+){3,5}\\\\s*\\\\n)"\n            let saltoLinea = ".+\\\\s+"\n            let saltoLinea2 = "";\n            \n            \n            let tes = "";\n            let testeo = new RegExp();\n            let condicion;\n\n            let i = 0;\n\n            while(!condicion && i <= 7){\n                saltoLinea2 += saltoLinea;\n\n                tes = a+saltoLinea2+b;\n                testeo = RegExp(tes,"i")\n                condicion = testeo.test(text)\n                \n                let matches = text.match(testeo);\n\n                    if(matches){\n                         propietario = matches[1];\n                        \n                    }\n                i++;\n            }\n        }\n    }else{\n        let regExp = /PROPIETARIO:\\s*([^\\n\\r]+)/;\n        let matches = text.match(regExp);\n        if(matches){\n              propietario = matches[1];\n              \n        }else{\n            propietario = "no se encontro el nombre del propietario"\n        }\n    }\n\n    let regExpModelo = /\\s+(\\d{4})\\n/;\n    let matchesModelo = text.match(regExpModelo);\n    if (matchesModelo) {\n        anio = matchesModelo[1];\n    } else {\n        anio = "No se encontr\xc3\xb3 el modelo del vehiculo";\n    }\n\n    let regExpPlacas = /\\s(\\w{3}\\d{3,4})\\n/;\n    let matchesPlacas = text.match(regExpPlacas);\n    if (matchesPlacas) {\n        placasJ = matchesPlacas[1];\n    } else {\n        placasJ = "No se encontraron las placas del veh\xc3\xadculo";\n    }\n\n        marcaJ = todasLasMarcas.find((marca) => {\n          const regexMarca = new RegExp(`^\\\\s*\\\\b${marca}\\\\b`, 'im');\n            return regexMarca.test(text);\n          });\n          \n          if (!marcaJ) {\n            marcaJ = "No se encontr\xc3\xb3 la marca";\n          }\n          \n        const lineas = text.split('\\n').slice(7); \n\n        modeloJ = todosLosModelos.find((modelo) => {\n            const regexModelo = new RegExp(`^\\\\s*\\\\b${modelo}\\\\b`, 'im');\n            return lineas.some((linea) => regexModelo.test(linea));\n          });\n        \n          if (!modeloJ) {\n            modeloJ = "No se encontr\xc3\xb3 el modelo";\n          }\n\n\n\n            const regexMotor = /[NUM]*[No.]*\\s*MOTOR:\\s*([\\w-]{5,20})/i;\n            const matchMotor = text.match(regexMotor);\n\n            if (matchMotor) {\n                const numeroMotor = matchMotor[1];\n                motorJ = numeroMotor;\n            } else {\n                motorJ = "No se encontr\xc3\xb3 el n\xc3\xbamero de motor en el texto";\n            }\n\n            let regexpNiv = /\\b[A-HJ-NPR-Z0-9]{17}\\b/i; //Omite O, Q y I\n            let matchesNiv = text.match(regexpNiv);\n            if (matchesNiv) {\n                nivJ = matchesNiv[0];\n                \n            } else {\n                nivJ="No se encontraron coincidencias para el NIV";\n            }\n\nconst fields = {\n  // owner: "",\n  // placas: "",\n  // modelo: "",\n  // serie: "",\n};\n\nfor (let i = 0; i < regexArray.length; i++) {\n  const regex = regexArray[i];\n  const match = text.match(regex);\n  if (match) {\n      const fieldName = Object.keys(fields)[i];\n      fields[fieldName] = match[0]?.trim()?.replace(/^(\\w+:)\\s*/, '');\n  }\n}\nconst car ={\n  owner: propietario,\n  placas: placasJ,\n  serie: nivJ, // Use serie or modelo if serie is not found\n  year: anio,\n  brand: marcaJ,\n  model: modeloJ,\n  motor: motorJ,\n  isConfirmed: false,\n  userUid:uid,\n  imageBucket\n}\n\n  logger.log(car)\n\n  admin.firestore().collection("Cars").add(car);\n  logger.log(car);\n})\n
Run Code Online (Sandbox Code Playgroud)\n

预先感谢您提供的任何帮助!

\n

我已经仔细检查了我的代码是否有任何语法错误或运行时问题,但找不到任何错误。还有其他可能的原因导致此错误吗?如何解决该问题并成功部署我的 Firebase 函数?

\n

任何见解或建议将不胜感激。谢谢你!

\n

Dir*_*k R 11

所以错误可能是任何事情。例如,根据您的规则,您可能会遇到权限错误。

有一种方法可以获取准确的错误消息,那就是--debug在部署时使用参数。

使用的完整命令是:

firebase deploy --only functions --debug
Run Code Online (Sandbox Code Playgroud)

使用它,您有望找出确切的问题,为您指明正确的方向。

  • 你救了我的命! (2认同)