【问题标题】:Firebase deploy returns error at tsc commandFirebase 部署在 tsc 命令返回错误
【发布时间】:2023-03-17 02:24:01
【问题描述】:

我设置了一个 Firebase 项目来创建一些基本的 Firebase 函数。
在我使用 TypeScript 的项目中

按照Firebase official documentation,我创建了我的项目。

最后一步,firebase deploy --only functionstsc 命令出错。

$ firebase deploy --only functions

=== Deploying to ‘my-project’…

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

> functions@ lint /path/to/functions
> tslint --project tsconfig.json

Running command: npm --prefix "$RESOURCE_DIR" run build

> functions@ build /path/to/functions
> tsc

node_modules/firebase-functions/lib/function-builder.d.ts(60,95): error TS1005: ';' expected.
node_modules/firebase-functions/lib/function-builder.d.ts(60,96): error TS1003: Identifier expected.
node_modules/firebase-functions/lib/function-builder.d.ts(60,116): error TS1005: ';' expected.
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!     /some/path/.npm/_logs/2019-02-03T00_10_30_573Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code2

Having trouble? Try firebase deploy --help

似乎某些 Firebase 库代码没有通过 tsc 编译/转译步骤。 我正在寻找使此部署步骤通过的方法。

我遵循了this GitHub issue 给出的建议,其中包括:

  • --skipLibCheck 添加到tsc 命令
  • skipLibCheck 添加到项目生成的functions/tsconfig.json
  • isolateModules 添加到functions/tsconfig.json
  • ./functions/node_modules/@types 添加到functions/tsconfig.json 文件中的typeRoots 数组中。
  • functions/tsconfig.json 中添加domcompilerOptions.lib

以上步骤都不适合我。

如何才能成功部署到 Firebase?

【问题讨论】:

  • 嗨 Rick,你是怎么解决这个问题的?如下更改版本效果不佳。你设法解决了这个问题吗?谢谢!!
  • 一年半前,成功了。查看接受的答案,升级到最新的 typescript 版本,清除缓存并重试,这些都是我会做的事情。

标签: node.js typescript firebase google-cloud-functions firebase-cli


【解决方案1】:

遇到同样的问题,将 typescript 库升级到 3.3.1 版本并执行 npm install 后能够部署。

在 package.json 文件集中 “开发依赖”:{ "tslint": "~5.8.0", “打字稿”:“~3.3.1” },

注意:您可以删除帖子中描述的所有更改。

【讨论】:

  • 谢谢,我使用typescript: 2.8.4 并更新到~3.1.1 完成了这项工作。
  • 这个答案并没有为我解决问题。但是OP提到的GitHub问题中有几个成功的解决方案。我发现关于向 tsconfig.json 添加类型根的方法是最好的:git.io/JeZrh
  • 根据我的经验,TS、FB、Angular、Ionic 的变化如此之快,以至于 7 个月前的问题和答案已经过时了。
【解决方案2】:

这对我有用: 将此行添加到函数文件夹中的 tsconfig:

"typeRoots": [ “node_modules/@types” ],

这是为我工作的“compilerOptions”块的一部分

【讨论】:

    【解决方案3】:

    试试这个

    在浪费了很多时间之后,当我取消注释index.ts中的代码时它起作用了

    import * as functions from "firebase-functions";
    
    // // Start writing Firebase Functions
    // // https://firebase.google.com/docs/functions/typescript
    //
    // export const helloWorld = functions.https.onRequest((request, response) => {
    //   functions.logger.info("Hello logs!", {structuredData: true});
    //   response.send("Hello from Firebase!");
    // });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-20
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多