New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import default issue with babel@6 #33
Comments
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 ***@***.***> wrote:
Firebase-functions version is 0.5.4
I am using ***@***.*** 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 ***@***.*** 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.<anonymous> (/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.<anonymous> (/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
<babel/babel#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
<#33>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAAD_q2IbXB28lEcIwiqZOBv9UnHWHkQks5rvD05gaJpZM4M64_q>
.
|
i deploying functions Error: Error occurred while parsing your function triggers. SyntaxError: Unexpected token = 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 |
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 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.
The text was updated successfully, but these errors were encountered: