【问题标题】:Hello I am getting error in deploying the function in firebase using javascript您好,我在使用 javascript 在 firebase 中部署函数时遇到错误
【发布时间】:2021-08-18 04:04:52
【问题描述】:

.eslintrx.js

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

index.js

let functions = require('firebase-functions');
let admin = require('firebase-admin');

admin.initializeApp();

exports.onConversationCreated;
onConversationCreated = functions.firestore.document("Conversations/chatID").onCreate((snapshot, context) => {
    let data = snapshot.data();
    let chatID = context.params.chatID;
    if (data) {
      let members = data.members;
      for (let index = 0; index < members.length; index++) {
        let currentUserID = members[index];
        let remainingUserIDs = members.filter((u= string) => u !== currentUserID);
        remainingUserIDs.forEach(async (m= string) => {
          try {
            let _doc = await admin.firestore().collection("Users").doc(m).get();
            let userData = _doc.data();
            if (userData) {
              return admin.firestore().collection("Users").doc(currentUserID).collection("Conversations").doc(m).create({
                "chatId": chatID,
                "image": userData.image,
                "name": userData.name,
                "unseenCount": 0,
              });
            }
            return null;
          } catch (e) {
            return null;
          }
        });
      }
    } return null;
  });

我得到的错误:

C:\Users\TOHID\Desktop\chat_firebase_function>firebase deploy --only functions

=== Deploying to 'chatapp-1b389'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint C:\Users\TOHID\Desktop\chat_firebase_function\functions
> eslint .


C:\Users\TOHID\Desktop\chat_firebase_function\functions\index.js
  15:52  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`enter code here`
npm ERR! 
npm ERR! Failed at the functions@ lint 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\TOHID\AppData\Roaming\npm-cache\_logs\2021-05-30T16_54_32_266Z-debug.log
events.js:353
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
    at notFoundError (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)    at verifyENOENT (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)    at ChildProcess.cp.emit (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.cp.emit (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
  path: 'npm --prefix "%RESOURCE_DIR%" run lint',
  spawnargs: []
}

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

Having trouble? Try firebase [command] --help

【问题讨论】:

  • 你可以试试this。看起来同样的问题。

标签: javascript google-cloud-functions


【解决方案1】:

我的情况和你一样,所以我把我的快速解决方案留给你。 预部署时“运行 lint”会导致错误,Unexpected token =&gt; ,但众所周知,这不是错误。

解决方案

  1. 清理掉.eslintrx.js后,它就可以工作了。

  2. 删除firebase.json 文件中的一些行。

    firebase.json 文件中,

    ...
      "functions": {
        "predeploy": [
          "npm --prefix \"$RESOURCE_DIR\" run lint"  << DELETE THIS LINE
        ]
      }
  • 如果您使用 Windows,\"$RESOURCE_DIR\" 应该是 \"%RESOURCE_DIR%\"
  1. ⭐⭐ 在index.js文件顶部添加/* eslint-disable */

    (我选择了这个)

  2. 如果你想持久化 eslint 预部署,请使用 eslint 配置文件。例如,

  env: {
    es6: true, -> es2017 or higher?? will it work??
    node: true,
  },

https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments

  1. 在 github 线程中查找更多信息: https://github.com/eslint/eslint/issues/8126

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-14
    • 2022-01-09
    • 1970-01-01
    • 2017-12-12
    • 2018-09-13
    • 2021-10-18
    • 2021-04-10
    • 2022-01-20
    相关资源
    最近更新 更多