【问题标题】:firebase cloud functions sample code errorfirebase 云函数示例代码错误
【发布时间】:2021-09-05 04:32:49
【问题描述】:

请帮忙:

我是 Firebase 云功能的新手,按照 Google 提供的启动指南操作时遇到以下问题。

下面是启动模板 index.js 文件

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');

// The Firebase Admin SDK to access Firestore.
const admin = require('firebase-admin');
admin.initializeApp();

 // Create and Deploy Your First Cloud Functions
 // https://firebase.google.com/docs/functions/write-firebase-functions

 exports.helloWorld = functions.https.onRequest((request, response) => {
   functions.logger.info("Hello logs!", {structuredData: true});
   response.send("Hello from Firebase!");
 });

当我在终端中输入firebase deploy 时。它给了我这些错误代码:

-  1:1   error  This line has a length of 85. Maximum allowed is 80  max-len
-  2:27  error  Strings must use doublequote                         quotes
-  5:23  error  Strings must use doublequote                         quotes
-  8:1   error  Expected indentation of 0 spaces but found 1         indent
-  9:1   error  Expected indentation of 0 spaces but found 1         indent
-  11:1   error  Expected indentation of 0 spaces but found 1         indent
-  12:1   error  Expected indentation of 2 spaces but found 3         indent
-  13:1   error  Expected indentation of 2 spaces but found 3         indent
-  14:1   error  Expected indentation of 0 spaces but found 1         indent

✖ 9 problems (9 errors, 0 warnings)
  8 errors and 0 warnings potentially fixable with the `--fix` option.

-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 logging output above.

-npm ERR! A complete log of this run can be found in:
-npm ERR!     C:\Users\alant\AppData\Roaming\npm-cache\_logs\2021-06-21T13_22_47_971Z-debug.log
-events.js:292
      throw er; // Unhandled 'error' event
      ^

-Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
    at notFoundError (C:\Users\alant\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\alant\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\alant\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\alant\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

【问题讨论】:

  • 在重新部署你的函数之前尝试运行npm install
  • @JMGelilio,我试过 npm install,但还是不行

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


【解决方案1】:

在终端中运行:

eslint --fix

【讨论】:

  • 我试过了不起作用。 eslintrc.js 文件:rules: { "indent": ["off", 2], quotes: ["error", "double"], }, C:\..\.eslintrc.js 13:5 错误不一致引用的属性 'quotes' 找到 quote-props C:\..\index.js 2:1 错误预期的空格或制表符在注释中的 '//' 之后 间隔注释 3:27 错误字符串必须使用双引号 6:23 错误字符串必须使用双引号 ✖ 4 个问题(4 个错误,0 个警告) 4 个错误和 0 个警告可能通过 --fix 修复选项。
  • 您需要在代码13:5 中修复所有这些错误; 2:1; ...
【解决方案2】:

@滨田 在研究了 eslint 文档之后。我终于做到了
在开头和结尾添加这个。

`/* eslint-disable */     

//My code (all rules will be disable)    

/* eslint-enable */`    

例如。

`// The Cloud Functions for Firebase SDK to  
// create Cloud Functions and setup triggers.  
/* eslint-disable */  
const functions = require('firebase-functions');  

// The Firebase Admin SDK to access Firestore.  
const admin = require('firebase-admin');  
admin.initializeApp();  

 // Create and Deploy Your First Cloud Functions  
 // https://firebase.google.com/docs/functions/write-firebase-functions  

 exports.helloWorld = functions.https.onRequest((request, response) => {    
   functions.logger.info("Hello logs!", {structuredData: true});  
   response.send("Hello from Firebase!");  
   /* eslint-enable */  
});`    

【讨论】:

    猜你喜欢
    • 2019-06-24
    • 1970-01-01
    • 2021-12-06
    • 2018-06-09
    • 2021-05-06
    • 1970-01-01
    • 2019-08-21
    • 2018-02-13
    • 1970-01-01
    相关资源
    最近更新 更多