0

I currently have a massive node JS file (3100+ line of code) and I am trying to split it up into multiple files. I have taken one of the functions and a bunch of firebase database references and put them into their own file inside their own class. For some reason the Firebase references give me an error no matter what even when the syntax seams to be okay:

/.../lib/context.js:13
        static database = firebase.database()
                        ^
SyntaxError: Unexpected token =

Here is my code for importing the file

// index.js
'use strict'

    var ... = ...()
    ...
    var util = require('util')
    var fs = require('fs')
    var http = require('http')
    var firebase = require('firebase')
    var Context = require('./lib/context.js')

and here is my code of the imported file:

'use strict'

var util = require('util')
var firebase = require('firebase')

exports.Context = class
{
    constructor()
    {

    }

    static database = firebase.database()
    static homeworkRef = database.ref("/homework")
    static usersRef = database.ref("/users")
    static announcementsRef = database.ref("/announcements")
    static votingRef = database.ref("/voting")
    static feedbackRef = database.ref("/feedback")
    static peerRef = database.ref("/peer_review")

Am I requiring the file correctly? Why does this error keep happening? It worked fine while it was in one file.

pjtnt11
  • 495
  • 2
  • 5
  • 22
  • 1
    `static database = firebase.database()` is not valid JavaScript. This seems to be using the [public class fields proposal](https://tc39.github.io/proposal-class-public-fields/). In order to make that work the files have to be transpiled to current JavaScript first. – Felix Kling Aug 18 '16 at 00:43
  • 1
    Possible duplicate of [Declaring static constants in ES6 classes?](http://stackoverflow.com/questions/32647215/declaring-static-constants-in-es6-classes) – Alexander O'Mara Aug 18 '16 at 00:45
  • OP: After making your source code change have you tried re-installing dependencies? I mean; Have you rm -rf node_modules && npm install yet? Felix Kling is correct, you need to transpile this to ES2015 via Babel or similar tooling before executing this. – Jeremy Anderson Aug 23 '16 at 02:00

0 Answers0