首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误的Firebase cli云功能部署。npm错误!函数@ lint脚本失败

错误的Firebase cli云功能部署。npm错误!函数@ lint脚本失败
EN

Stack Overflow用户
提问于 2021-10-06 07:13:51
回答 1查看 1.1K关注 0票数 0

我正在尝试使用firebase将类型记录云功能部署到google云中。我之所以这样做,是因为我有一个javascript函数,它为我提供了有关估计firebase环境变量的警告。所以使用火基的cli有效。

现在,我在打字稿中有了另一个功能。

6.14.15

  • firebase: 9.19.0

  • 节点: 14.17.6

,这是代码。

代码语言:javascript
复制
"use strict";

import cbor = require("cbor");

import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import iot = require("@google-cloud/iot");
const client = new iot.v1.DeviceManagerClient();

// start cloud function
exports.configFirestorev2 = functions
    .region("europe-west1")
    .firestore
    .document("Configs/{deviceId}")
    .onWrite(async (change: functions.Change<admin.firestore.DocumentSnapshot>,
        context?: functions.EventContext) => {
      if (context) {
        console.log(context.params.deviceId);
        const request = generateRequest(context.params.deviceId, change.after.data(), false);
        return client.modifyCloudToDeviceConfig(request);
      } else {
        throw (Error("no context from trigger"));
      }
    });

function generateRequest(deviceId: string, configData: any, isBinary: boolean) {
  const formattedName = client.devicePath(process.env.GCLOUD_PROJECT!, functions.config().iot.core.region, functions.config().iot.core.registry, deviceId);
  let dataValue;
  if (isBinary) {
    const encoded = cbor.encode(configData);
    dataValue = encoded.toString("base64");
  } else {
    dataValue = Buffer.from(JSON.stringify(configData)).toString("base64");
  }
  return {
    name: formattedName,
    binaryData: dataValue,
  };
}

这里是.eslintrc.js

代码语言:javascript
复制
module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "google",
    "plugin:@typescript-eslint/recommended",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: ["tsconfig.json", "tsconfig.dev.json"],
    sourceType: "module",
  },
  ignorePatterns: [
    "/lib/**/*", // Ignore built files.
  ],
  plugins: [
    "@typescript-eslint",
    "import",
  ],
  rules: {
    "quotes": ["error", "double"],
    "import/no-unresolved": 0,
  }, 
};

这里是package.json文件

代码语言:javascript
复制
{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1",
    "@google-cloud/iot": "2.0.0",
    "@types/cbor": "^5.0.0",
    "cbor": "^5.0.2"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.8.0",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^3.8.0"
  },
  "private": true
}

当我尝试使用firebase deploy --only functions部署它时

我得到一个错误,请参阅终端日志。

代码语言:javascript
复制
PS C:\firebase\configFirestore\functions> firebase deploy --only functions

=== Deploying to 'pti-tag-copy'...

i  deploying functions
Running command: npm --prefix functions run lint && npm --prefix functions run build

> functions@ lint C:\firebase\configFirestore\functions
> tslint -p tslint.json

'tslint' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `tslint -p tslint.json`
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\Shabir\AppData\Roaming\npm-cache\_logs\2021-10-06T06_44_06_259Z-debug.log
events.js:377
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm --prefix functions run lint && npm --prefix functions run build ENOENT
    at notFoundError (C:\Users\Shabir\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\Shabir\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\Shabir\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\Shabir\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 functions run lint && npm --prefix functions run build',
  path: 'npm --prefix functions run lint && npm --prefix functions run build',
  spawnargs: []
}

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

,这里是一个完整的调试日志

代码语言:javascript
复制
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   '--prefix',
1 verbose cli   'functions',
1 verbose cli   'run',
1 verbose cli   'lint'
1 verbose cli ]
2 info using npm@6.14.15
3 info using node@v14.17.6
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions@~prelint: functions@
6 info lifecycle functions@~lint: functions@
7 verbose lifecycle functions@~lint: unsafe-perm in lifecycle true
8 verbose lifecycle functions@~lint: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\firebase\configFirestore\functions\node_modules\.bin;C:\Users\Shabir\AppData\Local\cloud-code\installer\google-cloud-sdk\bin;C:\Users\Shabir\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\Shabir\AppData\Local\Programs\Python\Python39\;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\php-8.0.3-Win32-vs16-x64;C:\Program Files\dotnet\;C:\Program Files\Go\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\Intel(R) Memory and Storage Tool\;C:\Program Files\nodejs\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin;C:\Program Files\MinGW\bin;C:\Users\Shabir\AppData\Local\Microsoft\WindowsApps;;C:\Users\Shabir\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Shabir\AppData\Roaming\cabal\bin;C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.10.4\bin;C:\tools\msys64;C:\Users\Shabir\go\bin;C:\Users\Shabir\AppData\Roaming\npm
9 verbose lifecycle functions@~lint: CWD: C:\firebase\configFirestore\functions
10 silly lifecycle functions@~lint: Args: [ '/d /s /c', 'tslint -p tslint.json' ]
11 silly lifecycle functions@~lint: Returned: code: 1  signal: null
12 info lifecycle functions@~lint: Failed to exec lint script
13 verbose stack Error: functions@ lint: `tslint -p tslint.json`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:400:28)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:400:28)
13 verbose stack     at maybeClose (internal/child_process.js:1055:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid functions@
15 verbose cwd C:\firebase\configFirestore
16 verbose Windows_NT 10.0.22468
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "--prefix" "functions" "run" "lint"
18 verbose node v14.17.6
19 verbose npm  v6.14.15
20 error code ELIFECYCLE
21 error errno 1
22 error functions@ lint: `tslint -p tslint.json`
22 error Exit status 1
23 error Failed at the functions@ lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-07 08:44:19

我没有复制您的问题,但通过以下步骤,我能够在Debian环境中部署您的功能:

运行以下命令(我选择了TS,并在所有options)

  • cd functions

  • npm install cbor

  • npm install @google-cloud/iot

  • Copied中选择了是,您的函数位于functions/src/index.ts

  • I修改的the.eslintrc.js.

  • I运行firebase deploy --only functions

目录中)

.eslintrc.js中,我在规则部分中添加了以下几行:

代码语言:javascript
复制
"max-len": ["error", {"code": 200}],
"require-jsdoc": 0,

这是最后一个.eslintrc.js

代码语言:javascript
复制
module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "google",
    "plugin:@typescript-eslint/recommended",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: ["tsconfig.json", "tsconfig.dev.json"],
    sourceType: "module",
  },
  ignorePatterns: [
    "/lib/**/*", // Ignore built files.
  ],  plugins: [
    "@typescript-eslint",
    "import",
  ],
  rules: {
    "quotes": ["error", "double"],
    "import/no-unresolved": 0,
    "max-len": ["error", {"code": 200}],
    "require-jsdoc": 0,
  },
};

你能证实你遵循了这个步骤吗?

编辑

如评论中所述。这个问题是通过遵循这个answer中的步骤解决的。总之,OP所做的是将tsconfigRootDir设置为.eslintrc.js文件中的__dirname

代码语言:javascript
复制
module.exports = {
  // ...
  parserOptions: {
    project: "tsconfig.json",
    tsconfigRootDir: __dirname,
    sourceType: "module",
  },
  // ...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69461312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档