Closed stevenyap closed 7 years ago
You can just do
import * as functions from 'firebase-functions'
The lack of a default export is intentional and necessary for compatibility.
On Tue, Apr 11, 2017, 7:55 PM Steven Yap notifications@github.com wrote:
Firebase-functions version is 0.5.4
I am using babel@6 to transpile my es6 code and found an issue that the transpiled code is not working. Here's how to reproduce:
import functions from 'firebase-functions' export const helloWorld = functions.https.onRequest((request, response) => { response.send('Hello World!') })
which is transpiled into (using babel@6 es2015 preset):
'use strict'; Object.defineProperty(exports, "__esModule", { value: true });exports.helloWorld = undefined; var _firebaseFunctions = require('firebase-functions'); var _firebaseFunctions2 = _interopRequireDefault(_firebaseFunctions); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var helloWorld = exports.helloWorld = _firebaseFunctions2.default.https.onRequest(function (request, response) { response.send('Hello World!'); });
which produces the following error when deploying:
i deploying functions i functions: ensuring necessary APIs are enabled... i runtimeconfig: ensuring necessary APIs are enabled... ✔ runtimeconfig: all necessary APIs are enabled ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading... Error: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'https' of undefined at Object.
(/private/var/folders/6q/__dzccnj1p7_k7vz2qp2ntdr0000gn/T/fbfn_21971bAqbpyOqCko0/index.js:14:66) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object. (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:16:9) at Module._compile (module.js:571:32) I think the issue is that firebase-functions did not export a default and hence, when importing a default (import functions from 'firebase-functions'), the transpiled code does not work. This could be related to babel's T2212 Kill CommonJS default export behaviour https://github.com/babel/babel/issues/2212.
A quick workaround is to import the individual package instead of importing the default:
import { https } from 'firebase-functions' export const helloWorld = https.onRequest((request, response) => { response.send('Hello World!') })
which transpiles into:
'use strict'; Object.defineProperty(exports, "__esModule", { value: true });exports.helloWorld = undefined; var _firebaseFunctions = require('firebase-functions'); var helloWorld = exports.helloWorld = _firebaseFunctions.https.onRequest(function (request, response) { response.send('Hello World!'); });
which has no issue to run and to deploy.
The fix should be a relatively easy one which is to explicitly export a default in firebase-functions.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-functions/issues/33, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAD_q2IbXB28lEcIwiqZOBv9UnHWHkQks5rvD05gaJpZM4M64_q .
i deploying functions i functions: ensuring necessary APIs are enabled... i runtimeconfig: ensuring necessary APIs are enabled... ✔ runtimeconfig: all necessary APIs are enabled ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading...
Error: Error occurred while parsing your function triggers.
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.
may i know why am i getting this
Hi @achuthhadnoor, which version of node are you using? Can you paste here the result of running node --version
?
Hi @justinrosenthal the node version I use is v4.4.5
@achuthhadnoor That's likely why you're having problems. You should upgrade (or install via nvm
) to Node v6.11.1 as mentioned in the Getting Started guide.
v6 supports many more language features than v4, you can find more information here: http://node.green/
Firebase-functions version is 0.5.4
I am using babel@6 to transpile my es6 code and found an issue that the transpiled code is not working. Here's how to reproduce:
which is transpiled into (using babel@6 es2015 preset):
which produces the following error when deploying:
I think the issue is that firebase-functions did not export a default and hence, when importing a default (
import functions from 'firebase-functions'
), the transpiled code does not work. This could be related to babel's T2212 Kill CommonJS default export behaviour.A quick workaround is to import the individual package instead of importing the default:
which transpiles into:
which has no issue to run and to deploy.
The fix should be a relatively easy one which is to explicitly export a default in firebase-functions.