我目前正在 ES6 中编写我的云函数,并使用 Babel 进行转换以针对 Node v10 环境。而且我注意到了一些奇怪的事情。
为什么当我这样导入时firebase-functions:
import functions from 'firebase-functions';
我收到此错误:
! TypeError: Cannot read property 'https' of undefined
at Object.<anonymous> (C:\myProject\functions\index.js:28:55)
Run Code Online (Sandbox Code Playgroud)
为了修复它,我需要像这样导入它:
import * as functions from 'firebase-functions';
虽然以下import适用于firebase-admin:
import admin from 'firebase-admin';
题
简而言之,问题是:
这是为什么:
import functions from 'firebase-functions'; // DOESN'T WORK
import * as functions from 'firebase-functions'; // WORKS
import admin from 'firebase-admin'; // WORKS
Run Code Online (Sandbox Code Playgroud) javascript node.js firebase google-cloud-functions firebase-admin