1

index.js

const functions = require('firebase-functions');
var admin = require('firebase-admin');
//var app = admin.initializeApp();

export const helloWorld = functions.https.onRequest((request, response) => {
    console.log('HELLO MY SON!')
    response.send("Hello my son");
 });

I am just trying to deploy a simple Hello World function to my Google Cloud Platform project (also happens when i try to deploy functions for my Admin SDK), however when i enter firebase deploy into the terminal i get an error saying

Error occurred while parsing your function triggers

It highlights export in my function as an unexpected token. I have tried commenting out the initialising of the admin (which did nothing) and also tried downgrading my version of firebase-tools but that only caused my server to timeout after deploying.

Can anyone please highlight where i am going wrong with my approach please?

UPDATED: I also changed the parserOptions of my eslintrc.json file and added a sourcType

eslintrc.json

{
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module"
  },
  "plugins": [
    "promise"
  ],
  "extends": "eslint:recommended",
  "rules": {
    // Removed rule "disallow the use of console" from recommended eslint rules
    "no-console": "off",

    // Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
    "no-regex-spaces": "off",

    // Removed rule "disallow the use of debugger" from recommended eslint rules
    "no-debugger": "off",

    // Removed rule "disallow unused variables" from recommended eslint rules
    "no-unused-vars": "off",

    // Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules
    "no-mixed-spaces-and-tabs": "off",

    // Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules
    "no-undef": "off",

    // Warn against template literal placeholder syntax in regular strings
    "no-template-curly-in-string": 1,

    // Warn if return statements do not either always or never specify values
    "consistent-return": 1,

    // Warn if no return statements in callbacks of array methods
    "array-callback-return": 1,

    // Require the use of === and !==
    "eqeqeq": 2,

    // Disallow the use of alert, confirm, and prompt
    "no-alert": 2,

    // Disallow the use of arguments.caller or arguments.callee
    "no-caller": 2,

    // Disallow null comparisons without type-checking operators
    "no-eq-null": 2,

    // Disallow the use of eval()
    "no-eval": 2,

    // Warn against extending native types
    "no-extend-native": 1,

    // Warn against unnecessary calls to .bind()
    "no-extra-bind": 1,

    // Warn against unnecessary labels    
    "no-extra-label": 1,

    // Disallow leading or trailing decimal points in numeric literals
    "no-floating-decimal": 2,

    // Warn against shorthand type conversions
    "no-implicit-coercion": 1,

    // Warn against function declarations and expressions inside loop statements
    "no-loop-func": 1,

    // Disallow new operators with the Function object
    "no-new-func": 2,

    // Warn against new operators with the String, Number, and Boolean objects
    "no-new-wrappers": 1,

    // Disallow throwing literals as exceptions
    "no-throw-literal": 2,

    // Require using Error objects as Promise rejection reasons
    "prefer-promise-reject-errors": 2,

    // Enforce “for” loop update clause moving the counter in the right direction
    "for-direction": 2,

    // Enforce return statements in getters
    "getter-return": 2,

    // Disallow await inside of loops
    "no-await-in-loop": 2,

    // Disallow comparing against -0
    "no-compare-neg-zero": 2,

    // Warn against catch clause parameters from shadowing variables in the outer scope
    "no-catch-shadow": 1,

    // Disallow identifiers from shadowing restricted names
    "no-shadow-restricted-names": 2,

    // Enforce return statements in callbacks of array methods
    "callback-return": 2,

    // Require error handling in callbacks
    "handle-callback-err": 2,

    // Warn against string concatenation with __dirname and __filename
    "no-path-concat": 1,

    // Prefer using arrow functions for callbacks
    "prefer-arrow-callback": 1,

    // Return inside each then() to create readable and reusable Promise chains.
    // Forces developers to return console logs and http calls in promises. 
    "promise/always-return": 2,

    //Enforces the use of catch() on un-returned promises
    "promise/catch-or-return": 2,

    // Warn against nested then() or catch() statements
    "promise/no-nesting": 1
  }
}
 
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
CadyOG
  • 155
  • 9

1 Answers1

3

export is not a valid token in CommonJS. Therefore you cannot use it in a Node.js environment. The correct syntax should be something like:

exports.helloWorld = functions.https.onRequest((request, response) => {
  console.log('HELLO MY SON!')
  response.send("Hello my son");
});

Related post: Getting Unexpected Token Export

Hiranya Jayathilaka
  • 7,180
  • 1
  • 23
  • 34