Firebase Cloud 函数:Typescript 无法编译为 JavaScript

Sam*_*ami 3 node.js firebase typescript google-cloud-functions

我的计算机上的云功能可以使用 Javascript,但是当我使用 TypeScript 尝试它时,它不会编译为 Javascript。它不会创建 lib/index.js 事件

\n\n

当我运行 firebase 部署时,它显示以下错误

\n\n
Error: There was an error reading functions/package.json:\n
Run Code Online (Sandbox Code Playgroud)\n\n

firebase deploy --debug 显示以下日志:

\n\n
APPLEs-MacBook-Air:functions abbasi$ firebase deploy --debug\n[2020-01-08T08:39:06.383Z] ----------------------------------------------------------------------\n[2020-01-08T08:39:06.390Z] Command:       /usr/local/bin/node /usr/local/bin/firebase deploy --debug\n[2020-01-08T08:39:06.390Z] CLI Version:   7.11.0\n[2020-01-08T08:39:06.390Z] Platform:      darwin\n[2020-01-08T08:39:06.391Z] Node Version:  v12.14.1\n[2020-01-08T08:39:06.392Z] Time:          Wed Jan 08 2020 13:39:06 GMT+0500 (Pakistan Standard Time)\n[2020-01-08T08:39:06.393Z] ----------------------------------------------------------------------\n[2020-01-08T08:39:06.393Z] \n[2020-01-08T08:39:06.422Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]\n[2020-01-08T08:39:06.423Z] > authorizing via signed-in user\n[2020-01-08T08:39:06.426Z] [iam] checking project safepay-test for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]\n[2020-01-08T08:39:06.429Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/safepay-test:testIamPermissions  \n permissions=[cloudfunctions.functions.create, cloudfunctions.functions.delete, cloudfunctions.functions.get, cloudfunctions.functions.list, cloudfunctions.functions.update, cloudfunctions.operations.get, firebase.projects.get]\n[2020-01-08T08:39:08.205Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Wed, 08 Jan 2020 08:39:08 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, server-timing=gfet4t7; dur=1374, alt-svc=quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000, accept-ranges=none, transfer-encoding=chunked\n\n=== Deploying to \'safepay-test\'...\n\ni  deploying functions\nRunning command: npm --prefix "$RESOURCE_DIR" run lint\nRunning command: npm --prefix "$RESOURCE_DIR" run build\n\xe2\x9c\x94  functions: Finished running predeploy script.\n[2020-01-08T08:39:13.911Z] > [functions] package.json contents: {\n  "name": "functions",\n  "scripts": {\n    "lint": "tslint --project tsconfig.json",\n    "build": "tsc",\n    "serve": "npm run build && firebase serve --only functions",\n    "shell": "npm run build && firebase functions:shell",\n    "start": "npm run shell",\n    "deploy": "firebase deploy --only functions",\n    "logs": "firebase functions:log"\n  },\n  "engines": {\n    "node": "8"\n  },\n  "main": "lib/index.js",\n  "dependencies": {\n    "firebase-admin": "^8.6.0",\n    "firebase-functions": "^3.3.0"\n  },\n  "devDependencies": {\n    "tslint": "^5.12.0",\n    "typescript": "^3.2.2",\n    "firebase-functions-test": "^0.1.6"\n  },\n  "private": true\n}\n\nError: There was an error reading functions/package.json:\n\n functions/lib/index.js does not exist, can\'t deploy Cloud Functions\n\nHaving trouble? Try firebase [command] --help\n
Run Code Online (Sandbox Code Playgroud)\n\n

我刚刚在另一位同事的 Macbook 上尝试过,它在他的系统上完美运行,但在我的系统上却不行。

\n\n

请帮我解决这个问题。

\n

Fel*_*aro 5

我遇到了同样的问题:\nTypescript 无法编译。记录很多错误,主要是这样的:“错误 TS2300:重复标识符‘AbortController’”

\n

解决方案:

\n

只需在 tsconfig.json 文件的“compilerOptions”属性中添加以下行:

\n

"typeRoots": ["node_modules/@types"] \xc2\xa0

\n

像那样:

\n

/functions/tsconfig.json

\n
\n{ \n  {\n    "compilerOptions": {\n      "module": "commonjs",\n      "noImplicitReturns": true,\n      "noUnusedLocals": true,\n      "outDir": "lib", \n      "sourceMap": true,\n      "strict": true,\n      "target": "es2017",\n      "typeRoots": ["node_modules/@types"]  // <-- here\n    },  \n    "compileOnSave": true,\n    "include": ["src"]\n  }\n}\n\n\n
Run Code Online (Sandbox Code Playgroud)\n

之后就编译好了!

\n