Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

yarn serve not work #4

Closed
sarovin opened this issue Aug 7, 2017 · 19 comments
Closed

yarn serve not work #4

sarovin opened this issue Aug 7, 2017 · 19 comments

Comments

@sarovin
Copy link

sarovin commented Aug 7, 2017

hi,
when i run yarn serve and go in to the url http://localhost:5000 i receive this error:

info: User function triggered, starting execution
info: Execution took 2897 ms, finished with status: 'crash'
127.0.0.1 - - [07/Aug/2017:17:46:19 +0000] "GET / HTTP/1.1" 500 99 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
info: Execution took 65889 ms, finished with status: 'timeout'
Error: Can't set headers after they are sent.

Have you this error??

@sarovin
Copy link
Author

sarovin commented Aug 7, 2017

i have fixed the problem with var app = next({ dev: false, conf: { distDir: "next" } })

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

have you problem with var app = next({ dev: true, conf: { distDir: "next" } })???
I think that we must be increase the timeout of the cloud function...
@jthegedus

@jthegedus
Copy link
Owner

Hi @sarovin, I don't have any errors with either {dev: true, or {dev: false,.

Can you post your pkg.json files?

I found some other issues when using versions of packages < these:

"firebase-admin": "^5.0.1",
"firebase-functions": "^0.6.0",
"next": "beta",

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

i have the same versions...

@jthegedus
Copy link
Owner

jthegedus commented Aug 8, 2017

Are you producing this error on a clone of this repo or have you modified things? Because I can't reproduce the error. I didn't even know that you could Timeout locally served Firebase Functions! I've asked some q's on the Firebase community Slack channel to see if a Firebaser can advise on this error.

To be clear, you got it to work fine with dev:false, but dev:true throws that same error you originally posted?

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

@i have changed the serve script with this "serve": "firebase serve --port 5000 --only functions,hosting",

If i use only firebase serve i have this error:
Error: NOT_FOUND

my firebase-tools version is 3.9.2...

@jthegedus
Copy link
Owner

jthegedus commented Aug 8, 2017

I'm also using that version of firebase-tools. This leads me to believe there is some other issue going on here because you should be able to just use firebase serve.

When using

"serve": "firebase serve --port 5000 --only functions,hosting",

I had this console output
yarn-serve
and the browser showed this error
internal error occurred while connecting to Cloud Function "next"

But with just

"serve: "firebase serve"

I did not have the error functions: Cannot start emulator. Error: Cannot find module '@google-cloud... in the console and the page is hosted correctly.

Maybe this is a Node or Yarn version issue? I've got:
Node: v6.11.1
Yarn: 0.27.5

Failing that, I imagine solving the issue with using firebase serve may fix this issue. You should be able to use it just fine so something is amiss there.

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

When using

"serve": "firebase serve --port 5000 --only functions,hosting"

you must wait this line:

i  hosting: Serving hosting files from: build/public
✔  hosting: Local server: http://localhost:5000

✔  functions: next: http://localhost:5001/<Project-name>/us-central1/next

Node: v7.4.0
Yarn: 0.27.5

@jthegedus
Copy link
Owner

jthegedus commented Aug 8, 2017

That line only shows once I attempt to load the page. I still get an error asking for the Google Cloud Function emulator.

yarn serve

and the page errors of course.
yarn serve 02

The google-cloud/functions-emulator may be causing interference with firebase serve if it's also a global package.

@jthegedus
Copy link
Owner

jthegedus commented Aug 8, 2017

Solved it! Try this:

"serve": "firebase serve --port 5000 --only hosting"

instead of:

"serve": "firebase serve --port 5000 --only hosting,functions"

I noticed that when I used "serve": "firebase serve" the console output did say anything about functions.
yarn serve 03

It seems that the rewrite rule in firebase.json does everything required to host the functions without us needing to specify anything.

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

i don't understand...you not serve the functions???

@jthegedus
Copy link
Owner

It seems that when you deploy Firebase Hosting with a Rewrite rule in the firebase.json it knows that there is a function and handles serving the function for you.

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

and if i not deploy but run only serve?
@jthegedus My goal is running nextjs app in development mode in localhost

@jthegedus
Copy link
Owner

jthegedus commented Aug 8, 2017

Yes.

So when you run firebase deploy, it deploys both the Cloud Function and the Hosting. When you run firebase serve it serves the Hosting, but part of that configuration involves a Cloud Function so it serves the ones it needs behind the scenes.

Try this:

"serve": "firebase serve --port 5000 --only hosting"

it works.

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

...i have tested with "serve": "firebase serve --port 5000 --only hosting" but i have the same issue:

i  hosting: Serving hosting files from: src/public
✔  hosting: Local server: http://localhost:5000

127.0.0.1 - - [08/Aug/2017:15:34:35 +0000] "GET / HTTP/1.1" 404

@jthegedus
Copy link
Owner

Interesting. This may be a config problem in your firebase.json file. Do you mind sharing? If you can't share here you could add me as a read-only user to your repo.

@sarovin
Copy link
Author

sarovin commented Aug 8, 2017

See this repo => https://github.com/Bolket/next-firebase-functions/tree/development

@jthegedus
Copy link
Owner

jthegedus commented Aug 8, 2017

Bolket/next-firebase-functions#3
So I removed your slasher wrapper for your Cloud Function and it works fine now. Since you're rewriting all routes with **/** in the firebase.json every route without a / will end up at the Next.js app. Next.js already handles the issues around missing /s. You can still use the slasher wrapper for any other Cloud Functions you may create.

When your code was deployed it appeared to work fine, however, it was actually doing a full refresh of each route from the Next.js server instead of client-side caching (a part of Next.js). Removing the slasher from this Cloud Function fixed this issue too.

@jthegedus
Copy link
Owner

I like what you did including ES6+ transpiling with the nice folder structure too. I avoided that with this repo since I wanted to keep it as bare bones as possible so people who haven't read my other posts aren't lost. It gets complex pretty quickly. I'll be AFK for the next 12 hours, so hopefully, this solves your problems for now.

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

No branches or pull requests

2 participants