9

I am new to firebase and am trying to make a simple app that utilizes user authentication. At this point in the project I am trying to run firebase on a local server using CLI commands.
I have set up firebase init and firebase deploy. When I type firebase serve on my project folder i get the response,

"an unexpected error has occurred".

Below i am attaching the contents of my firebase-debug.log file. Any help would be appreciated. Thanks

command requires scopes:

["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase",... [debug] [2017-06-11T17:09:09.607Z] > authorizing via signed-in user

TypeError: Cannot read property 'public' of undefined

Varun Nath
  • 5,570
  • 3
  • 23
  • 39
Vince
  • 101
  • 2
  • 6

6 Answers6

11

Look in your firebase.json file, which you should have in the directory where you're running firebase serve. It should look something like this:

{
  "hosting": {
    "public": "app",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

If it doesn't have that "hosting" key, then you'll get that Cannot read property 'public' of undefined error because firebase serve tries to access .hosting.public.

davidvgalbraith
  • 401
  • 5
  • 16
  • 1
    after running firebase init - the firebase.json file is empty - ts this a bug if we have triggerd firebase functions only? – UKDataGeek Oct 08 '17 at 23:56
8

I faced this issue today, I ran it with --debug and found out that I've installed npm/node as sudo user, running following:

firebase serve

was giving me this error:

Error: An unexpected error has occurred.

When I ran it with sudo, I was able to deploy hosting and functions locally:

sudo firebase serve --debug --only hosting,functions
thekosmix
  • 1,705
  • 21
  • 35
3

1) create a folder called "public" and put your files inside.

2) edit the firebase.json and just write this:

{ 
 "hosting": {
"public": "public" 
}
}
Mike Brian Olivera
  • 1,414
  • 1
  • 16
  • 21
1

This appears to be a bug - that ideally should be resolved with Firebase Init. I have logged a support ticket with Firebase, and would encourage others to do so as well.

UKDataGeek
  • 6,338
  • 9
  • 46
  • 63
0

I think you may have skipped an initialization step by accident (I did the same thing on my first run-through)

Try this (from your same project directory):

1) firebase init

2) When prompted for which services you'll need make sure that Database AND Hosting options have their markers highlighted green (tab to Hosting with the spacebar). It's easy to select just database and let it run its configuration and assume it configures all of the bulleted options below it if you do not watch closely because the stdout info isn't very clear. Now hit Enter

3) Accept the default database settings as you probably did before, and when asked "What do you want to use as your public directory? (public)", hit Enter.

At this point you should be good to go spin up a local firebase web server...

4) try 'firebase serve', hit Enter, and you should get a verification that hosting files are being served from /public

Hope this helps. Good luck.

Ryan
  • 1
  • 2
0

As for me the error is (--debug attr)

Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/logs'

So the solution will be to run with sudo

Vlad
  • 7,997
  • 3
  • 56
  • 43