Skip to content
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

Error on firebase serve "An unexpected error has occurred." #485

Closed
cristoferfb opened this issue Oct 3, 2017 · 16 comments
Closed

Error on firebase serve "An unexpected error has occurred." #485

cristoferfb opened this issue Oct 3, 2017 · 16 comments
Assignees

Comments

@cristoferfb
Copy link

Version info

3.12.0

Steps to reproduce

I work in macOS Sierra
1.- firebase init
2.- create a index.html
3.- firebase server
ERROR
I reinstalled firebase-tools

Expected behavior

Start a local server

Actual behavior

[debug] [2017-10-03T02:27:50.194Z] ----------------------------------------------------------------------
[debug] [2017-10-03T02:27:50.197Z] Command: /usr/local/Cellar/node/8.5.0/bin/node /usr/local/bin/firebase serve
[debug] [2017-10-03T02:27:50.197Z] CLI Version: 3.12.0
[debug] [2017-10-03T02:27:50.197Z] Platform: darwin
[debug] [2017-10-03T02:27:50.197Z] Node Version: v8.5.0
[debug] [2017-10-03T02:27:50.198Z] Time: Mon Oct 02 2017 23:27:50 GMT-0300 (-03)
[debug] [2017-10-03T02:27:50.198Z] ----------------------------------------------------------------------
[debug]
[debug] [2017-10-03T02:27:50.211Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2017-10-03T02:27:50.211Z] > authorizing via signed-in user
[debug] [2017-10-03T02:27:50.214Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2017-10-03T02:27:50.214Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token { refresh_token: '1/XIefl2qhxtkuDgmPe_cio0pfzWJt-JWWGo-MFXs5wrk',
client_id: '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com',
client_secret: 'j9iVZfS8kkCEFUPaAeJV0sAi',
grant_type: 'refresh_token',
scope: 'email https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase openid' }
Mon Oct 02 2017 23:27:50 GMT-0300 (-03)
[debug] [2017-10-03T02:27:50.649Z] <<< HTTP RESPONSE 200
[debug] [2017-10-03T02:27:50.725Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/all-new-thiares-admin
Mon Oct 02 2017 23:27:50 GMT-0300 (-03)
[debug] [2017-10-03T02:27:52.357Z] <<< HTTP RESPONSE 200
[debug] [2017-10-03T02:27:52.358Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/all-new-thiares-admin/tokens
Mon Oct 02 2017 23:27:52 GMT-0300 (-03)
[debug] [2017-10-03T02:27:53.241Z] <<< HTTP RESPONSE 200
[info]
[info] === Serving from '/Users/cristoferfuentes/Documents/Proyectos/AllNewThiaresAdmin'...
[info]
[debug] [2017-10-03T02:27:53.244Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/all-new-thiares-admin
Mon Oct 02 2017 23:27:53 GMT-0300 (-03)
[debug] [2017-10-03T02:27:54.539Z] <<< HTTP RESPONSE 200
[debug] [2017-10-03T02:27:54.539Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/387704735326/clients/_:getWebAppConfig
Mon Oct 02 2017 23:27:54 GMT-0300 (-03)
[debug] [2017-10-03T02:27:55.998Z] <<< HTTP RESPONSE 200
[debug] [2017-10-03T02:27:56.015Z] TypeError: Cannot read property 'public' of undefined
at Server. (/usr/local/lib/node_modules/firebase-tools/lib/serve/hosting.js:34:17)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:105:13)
at Server.emit (events.js:207:7)
at emitListeningNT (net.js:1370:10)
at _combinedTickCallback (internal/process/next_tick.js:135:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
[error]
[error] Error: An unexpected error has occurred.

@laurenzlong
Copy link
Contributor

What does your firebase.json look like?

@laurenzlong laurenzlong self-assigned this Oct 3, 2017
@laurenzlong
Copy link
Contributor

I think you probably have a misformatted firebase.json. Best way to fix it is to ensure that firebase.json looks like:

{
...
"hosting": {
"public": "public"
}
}

Please re-open if this does not fix it.

@Kaisaurus
Copy link

Kaisaurus commented Mar 30, 2018

Had the same problem. the default firebase.json seems to be missing this. quite confusing for noobies like me..

@jamsheedpk
Copy link

jamsheedpk commented May 5, 2018

hi bug is sloved
firebase serve
change
sudo firebase serve

@kiranchenna
Copy link

kiranchenna commented Jun 10, 2018

In Mac to start a local server we have to giv admin rights or use sudo at start.

by using

$sudo firebase serve

problem fix.

@laurenzlong
Copy link
Contributor

If you installed firebase tools without using sudo (i.e. npm install -g firebase-tools not sudo npm install -g firebase-tools), then you shouldn't have to run any commands with sudo. If you are having trouble doing npm installs without sudo, then this is a helpful article on how to fix npm permissions: https://docs.npmjs.com/getting-started/fixing-npm-permissions

@neerajyadav
Copy link

@laurenzlong even though I installed firebase-tools without sudo, I need to use sudo permission while running firebase serve. Earlier it used to work without sudo, but now not. I'm using nvm. Here are the environment config.

  • nvm - 0.33.11
  • node - v10.11.0
  • firebase-tools - 6.3.0
  • I recently updated my os. os version is macOS Mojave 10.14.4 Beta. I don't know file permission read issue arise due to os upgrade.

Here is the error from firebase-debug.log.

[info] i  functions: Preparing to emulate functions.
[debug] [2019-01-30T09:54:05.574Z] Fetching environment
[debug] [2019-01-30T09:54:05.975Z] Error: EACCES: permission denied, open '/Users/a/.config/gcloud/application_default_credentials.json'
    at Object.openSync (fs.js:436:3)
    at Object.writeFileSync (fs.js:1168:35)
    at module.exports (/Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/lib/ensureDefaultCredentials.js:28:8)
    at FunctionsEmulator.start (/Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/lib/functionsEmulator.js:106:5)
    at Object.start (/Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/lib/serve/functions.js:7:33)
    at /Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/lib/serve/index.js:15:23
    at arrayMap (/Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/node_modules/lodash/lodash.js:639:23)
    at Function.map (/Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/node_modules/lodash/lodash.js:9556:14)
    at _serve (/Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/lib/serve/index.js:13:26)
    at Command.module.exports.Command.description.option.option.option.option.before.action [as _action] (/Users/a/.nvm/versions/node/v10.11.0/lib/node_modules/firebase-tools/lib/commands/serve.js:55:12)
[error] 
[error] Error: An unexpected error has occurred.

@thechenky
Copy link
Contributor

@neerajyadav Make sure your /Users/a/.config/gcloud/application_default_credentials.json file has the correct permissions. From the error that's being returned, the CLI is trying to read that file but doesn't have access to it.

@neerajyadav
Copy link

@thechenky I'm assuming this file is created when either when we install firebase-tools or when we do firebase login. I haven't created the file manually. So by default it should be created with permissions accessible to firebase-tools.

@bkendall
Copy link
Contributor

@neerajyadav can you open a new issue with the full contents of your debug log? It's easier to track new issues like this as... well, new issues. You have most of the information ready that the new issue template asks, and it would be great if you could provide the output of ls -al /Users/a/.config/gcloud/application_default_credentials.json as that will tell us what the permissions and owner are. Thanks!

@neerajyadav
Copy link

Sorry for late reply. I was busy with project work and didn't find enough time to look at it. @bkendall I created another bug #1136 with output from ls -al.

@olufemi424
Copy link

sudo firebase serve

@hpoit
Copy link

hpoit commented Jul 11, 2019

Hi @laurenzlong, I'm not sure I should be opening a new issue, for this one:

Matts-MBP:forms matt$ firebase serve

=== Serving from '/Users/matt/WebstormProjects/forms'...

✔  functions: Using node@12 from host.
✔  functions: Emulator started at http://localhost:5001
i  functions: Watching "/Users/matt/WebstormProjects/forms/functions" for Cloud Functions...
i  hosting: Serving hosting files from: build/web
✔  hosting: Local server: http://localhost:5000

Error: An unexpected error has occurred.
Matts-MBP:forms matt$ 

@hpoit
Copy link

hpoit commented Jul 11, 2019

Lauren, here's my package.json:

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "12"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.0.0"
  },
  "devDependencies": {
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  },
  "private": true
}

@hpoit
Copy link

hpoit commented Jul 11, 2019

firebase.json:

{
  "database": {
    "rules": "database.rules.json"
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "build/web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

"public": "build/web" is for AngularDart, which works.

@bkendall
Copy link
Contributor

@hpoit open a new issue with the required information (including relevant parts of the debug log). Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants