【发布时间】:2020-01-08 22:24:35
【问题描述】:
尝试在将用于 TypeScript 项目的空 git 存储库上跟踪 Add Firebase to your JavaScript project 时,运行 firebase deploy 时出现以下错误:
> functions@ build /Users/mosofsky/Documents/Developer/abcplan/functions
> tsc
src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read.
1 import * as functions from 'firebase-functions'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error.
npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! functions@ build: `tsc` npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the functions@ build 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/mosofsky/.npm/_logs/2019-09-06T03_00_54_557Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
由于我遵循 Google 的入门指南,我希望一切正常。
【问题讨论】:
-
您链接到的文档适用于在网络浏览器中运行的网络项目。 Cloud Functions 在后端运行,不使用 Web 客户端 SDK。运行 Cloud Functions 的后端项目使用 Firebase Admin SDK 来访问 Firebase 和 Google Cloud 产品。
-
@DougStevenson 记录在案的步骤包括
firebase init,它询问我想要哪些 Firebase 服务(以及哪种语言)。我选择了列出的所有服务和 TypeScript,因为说明没有说明要选择什么。其中之一肯定是 Cloud Functions。因此它生成了带有错误的functions/src/index.ts。 -
Firebase CLI 不会生成与 Web 客户端代码(您链接到的代码)相关的任何内容。 CLI 只处理后端代码。
-
firebase init确实生成了functions/src/index.ts@DougStevenson -
对,这就是后端代码。它不会在 Web 客户端中运行。我假设您想运行 Web 客户端代码,因为您的问题链接到 Web 设置说明。也许您的链接有误?
标签: typescript firebase