迁移到 Typescript 后无法部署 Firebase Cloud 功能

Cannot deploy Firebase Cloud function after migrating to Typescript

我刚刚按照 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
}

可能与描述的问题相同here

尝试切换到,

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

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

一天结束时,我还原了所有更改,清理了 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"
  }
}