【问题标题】:Cannot deploy Firebase Cloud function after migrating to Typescript迁移到 Typescript 后无法部署 Firebase Cloud 功能
【发布时间】:2021-03-20 01:38:59
【问题描述】:

我只是按照 firebase 文档 (https://firebase.google.com/docs/functions/typescript) 将我的云功能项目迁移到打字稿,现在,我在使用时出现以下错误:'firebase deploy --only functions'

这里是堆栈跟踪:

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

> functions@ lint (here is my project path)
> tslint -p tslint.json

Invalid option for project: tslint.json
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!     /Users/macbook/.npm/_logs/2020-12-08T17_25_16_433Z-debug.log

我的 tsconfig.json :

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "types": ["node"],
    "allowJs": true
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

我的 package.json :

{
  "name": "functions",
  "main": "./src/index.ts",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "./node_modules/.bin/tslint -p tslint.json",
    "build": "./node_modules/.bin/tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "12"
  },
  "dependencies": {
    "cors": "^2.8.5",
    "firebase-admin": "^9.4.1",
    "firebase-functions": "^3.13.0",
    "googleapis": "^39.2.0",
    "request": "^2.88.2",
    "tslint": "^6.1.3",
    "typedi": "^0.8.0",
    "typescript": "^4.1.2"
  },
  "devDependencies": {
    "@types/node": "^14.14.10",
    "firebase-functions-test": "^0.1.7"
  },
  "private": true
}

【问题讨论】:

  • 我已经尝试了几乎所有可以在谷歌上获得的东西,但我现在的想法真的很低。我无法推进我的项目,如果有人有想法,将不胜感激!
  • 能否请您添加您的云功能的代码?这能够复制以了解正在发生的事情。
  • 能够按照我的回答中所述使其工作。感谢您的关心!

标签: typescript firebase google-cloud-firestore google-cloud-functions tslint


【解决方案1】:

可能和here描述的问题一样

尝试切换到,

"lint": "./node_modules/.bin/tslint -p tslint.json .", 

或将. 替换为您要检查的目录的路径

【讨论】:

  • 不幸的是它没有改变任何东西:(
【解决方案2】:

最后,我恢复了所有更改,清理了 node_module 并再次重新开始迁移。

我暂时将索引保留为 .js 而不是 .ts 并且它有效。最后,这是我的conf,以防将来可以帮助某人:

package.json

{
  "name": "functions",
  "main": "src/index.js",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "build": "./node_modules/.bin/tslint --project tsconfig.json && ./node_modules/.bin/tsc",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "12"
  },
  "dependencies": {
    "cors": "^2.8.5",
    "firebase-admin": "^9.4.1",
    "firebase-functions": "^3.13.0",
    "tslint": "^6.1.3",
    "typescript": "^4.1.2"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.1.7"
  },
  "private": true
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
  "allowJs": "true"
}

firebase.json

{
  "functions": {
    "predeploy": "npm --prefix \"$RESOURCE_DIR\" run build"
  }
}

【讨论】:

    猜你喜欢
    • 2021-08-26
    • 2016-09-16
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 2020-12-24
    • 2017-11-15
    • 1970-01-01
    • 2018-08-20
    相关资源
    最近更新 更多