Firebase 函数的 Sourcemap 支持吗?

问题描述 投票:0回答:2

在打字稿中开发 firebase 函数时,我正在尝试让源映射正常工作。

在我的

tsconfig.json
文件中启用了源映射。

这生成了源映射。然后我将这一行包含在我的

index.ts
文件中:

import 'source-map-support/register';

然后它似乎起作用了。配置是否正确,以及

source-map-support
到项目
package.json
文件?

firebase google-cloud-functions
2个回答
10
投票

是的,您需要做一些事情,其中一些已记录在here

  1. npm install source-map-support

  2. 通过添加以下内容在

    sourceMap
    不是
    package.json!)中启用 tsconfig.json

  "compilerOptions": {
    "sourceMap": true,
    ...
  },
  1. 将库导入到您的文件中
    • 如果您使用 ES6 模块:
      import 'source-map-support/register'
    • 如果您使用 commonJS 模块:
      require('source-map-support').install();

结果将改变这一点:

TypeError: Cannot read property 'current_location' of null
    at /user_code/lib/http_actions.js:173:74
    at next (native)
    at fulfilled (/user_code/lib/http_actions.js:4:58)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

进入这个:

TypeError: Cannot read property 'current_location' of null
    at /user_code/src/http_actions.ts:183:33
    at next (native)
    at fulfilled (/user_code/lib/http_actions.js:4:58)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

0
投票

在部署该功能时设置

NODE_OPTIONS=--enable-source-maps
,您将不需要任何额外的导入。

不确定 firebase 功能,但它们基本上是谷歌云功能,你可以这样做

--set-env-vars NODE_OPTIONS=--enable-source-maps
在 gcloud 函数中部署。

© www.soinside.com 2019 - 2024. All rights reserved.