我正在尝试部署一个函数来减小上传到Firebase存储中的图像大小。
尝试使用使用 TypeScript 编写的函数部署函数时,会发生此错误。
我尝试执行部署的功能与下面的功能相同。https://angularfirebase.com/lessons/image-thumbnail-resizer-cloud-function/
**The following error is displayed:**
λ firebase deploy --only functions
=== Deploying to 'myProject1154'...
i deploying functions
Running command: npm --prefix "functions" run lint
> functions@ lint C:myAppfunctions
> tslint --project tsconfig.json
Running command: npm --prefix "functions" run build
> functions@ build C:myAppfunctions
> tsc
node_modules/@google-cloud/common/build/src/service-object.d.ts(72,45): error TS8020: JSDoc types can only be used inside documentation comments.
node_modules/@google-cloud/common/build/src/service-object.d.ts(72,45): error TS8028: JSDoc '...' may only appear in the last parameter of a signature.
node_modules/@google-cloud/common/node_modules/google-auth-library/build/src/auth/oauth2client.d.ts(291,55): error TS1039: Initializers are not allowed in ambient contexts.
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! C:UsersLUIZAppDataRoamingnpm-cache_logs2019-01-15T15_00_31_114Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
几天
前我遇到了同样的问题。您必须使用firebase-admin
中的存储对象,而不是google-cloud/storage
所以我的代码看起来像这样:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
admin.initializeApp(functions.config())
const storage = admin.storage()
然后后来
storage.bucket(fileBucket)