【问题标题】:Firebase deploy errors starting with non-zero exit codeFirebase 部署错误以非零退出代码开头
【发布时间】:2021-11-13 17:53:20
【问题描述】:

开发人员,我正在尝试将一个简单的云功能部署到 firebase 控制台,一切都运行良好(安装 npm & 配置 & 其他东西......)。

然后我在 index.js 文件中写了一个简单的函数:

'use strict'
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


exports.sendNotification  = functions.database.ref('/notififcation/{user_id}/{notififcation_id}').onWrite(

event =>
       {
    const user_id = event.params.user_id;
    const notififcation_id = event.params.notififcation_id;
    console.log('this id is the ' , user_id);
    
       }
):

然后,当我想使用此命令 firebase deploy 将其部署到 firebase 时,此错误不断出现, 这是错误:


C:\Users\nasro\Desktop\oussamaproject\notifyfun\functions\index.js
  14:2  error  Parsing error: Unexpected token :

? 1 problem (1 error, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional l
ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\nasro\AppData\Roaming\npm-cache\_logs\2021-09-19T21_28_2
892Z-debug.log
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm --prefix "C:\Users\nasro\Desktop\oussamaproject\notifyfun\fun
ions" run lint ENOENT
    at notFoundError (C:\Users\nasro\AppData\Roaming\npm\node_modules\firebase
ools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\nasro\AppData\Roaming\npm\node_modules\firebase-
ols\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\nasro\AppData\Roaming\npm\node_modules\f
ebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:2

    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.cp.emit (C:\Users\nasro\AppData\Roaming\npm\node_modules\f
ebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:3

    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn npm --prefix "C:\\Users\\nasro\\Desktop\\oussamaproject\\not
yfun\\functions" run lint',
  path: 'npm --prefix "C:\\Users\\nasro\\Desktop\\oussamaproject\\notifyfun\\f
ctions" run lint',
  spawnargs: []
}

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

所以在 firebase 文档和文章中搜索解决方案后,我尝试了这些解决方案

解决方案一: 默认在 firebase.json 中:

"predeploy": [
  "npm --prefix \"$RESOURCE_DIR\" run lint"
]

我修改为:

"predeploy": [
  "npm --prefix \"%RESOURCE_DIR%\" run lint"
]

该错误再次出现并显示相同的错误消息,所以我尝试了解决方案 2

解决方案二

我再次将文件 firebase.json 修改为:

"predeploy": [
         "npm --prefix \"%RESOURCE_DIR%\" run lint",
         "npm --prefix \"%RESOURCE_DIR%\" run build"
    ]

并且错误不断出现,并带有相同的错误消息(btw我使用的是 windows7)

所以对于这个错误的任何解决方案或建议..

【问题讨论】:

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


    【解决方案1】:

    onWrite 方法采用 2 个参数 - changecontext,参数位于 context 对象上。

    您可以尝试以下方法吗:

    functions.database.ref("/notififcation/{user_id}/{notififcation_id}").onWrite((change, context)=>{
        const user_id = context.params.user_id;
        const notififcation_id = context.params.notififcation_id;
        console.log("this id is the " , user_id);
    
        return null; // <----- please try returning something as well at the end
    });
    
    

    更多信息在这里 - https://firebase.google.com/docs/functions/database-events#reading_the_previous_value

    linting 似乎也存在问题,因此根据您在下面的评论出现了 linting 错误,或许可以尝试像这样更新项目中的 .eslintrc.js.eslintrc.json 文件:

    module.exports = { 
      root: true, 
      env: { es6: true, node: true, }, 
      extends: [ "eslint:recommended" ], // <--- remove google from here
      rules: { quotes: ["error", "double"], }
    };
    

    【讨论】:

    • 我从字面上复制粘贴您的代码,唯一改变的是消息错误:旧错误 + 这个新部分:
    • @Nặśř'Eddíŋě 您能否也尝试从该函数返回一些内容,以便它可以自行关闭。已经更新了我上面的答案以反映相同
    • 1:1 错误字符串必须使用双引号 1:13 错误缺少分号半 3:23 错误字符串必须使用双引号 6:1 错误 此行的长度为 98。允许的最大值为 80 max -len 6:24 错误字符串必须使用双引号 7:1 错误预期缩进 2 个空格,但发现缩进 4 个 7:11 错误标识符“user_id”不是骆驼大小写骆驼...
    • 好的,我会检查的
    • @Nặśř'Eddíŋě 从您粘贴的错误来看,谷歌似乎抛出了一些 lint 错误,例如 eslint 错误,您能否也检查一下 .eslintrc.js 或 @ 中的 lint 配置987654331@文件
    【解决方案2】:

    看起来您的函数以冒号而不是分号结尾。改成这样:

    "use strict";
    const functions = require("firebase-functions");
    const admin = require("firebase-admin");
    admin.initializeApp(functions.config().firebase);
    
    
    exports.sendNotification = functions.database
        .ref("/notififcation/{user_id}/{notififcation_id}")
        .onWrite((change, context) => {
          const userId = context.params.user_id;
          // const notififcationId = context.params.notififcation_id;
          console.log("this id is the ", userId);
        }
        );
    

    【讨论】:

    • 不,不是问题
    • @Nặśř'Eddíŋě 你能显示正在抛出的新错误吗?
    • 太长了,我把它分成几部分: 1:1 error Strings must use doublequote quotes 1:13 error Missing semicolon semi 3:23 error Strings must use doublequote quotes 6:1 error 这一行长度为 98。允许的最大值为 80 max-len 6:24 错误字符串必须使用双引号 7:1 错误预期缩进 2 个空格,但发现缩进 4 缩进 7:11 错误标识符“user_id”不是骆驼大小写骆驼
    • 8:1 错误预期缩进 2 个空格,但发现 4 个缩进 8:11 错误标识符 'notififcation_id' 不是骆驼大小写骆驼 8:11 错误'notifcation_id' 被分配了一个值,但从未使用过 否-unuse -vars 9:1 错误预期缩进 2 个空格,但发现 4 个缩进 9:17 错误字符串必须使用双引号 9:35 错误 ',' com 之前应该没有空格
    • cing 10:4 error 文件末尾需要换行符但未找到 eol-last .. .. _____ 然后旧错误再次出现(在这个新部分之后)
    猜你喜欢
    • 2018-07-06
    • 2020-04-07
    • 2018-06-29
    • 2021-04-13
    • 2018-07-21
    • 1970-01-01
    • 2022-08-10
    相关资源
    最近更新 更多