I’ve created a next.js project with this command:
npx create-next-app@latest testdemo
And select these options to create:
After that, I’ve run it locally, it works fine,
build is fine too And the build create .next folder and within that, it created the server/app/index.html and many other files too.
then I want to deploy it to firebase hosting, For that I’ve login to firebase console and then
I’ve hit firebase init command
and select these options:
After that, the firebase.json is look like:
{
"hosting": {
"source": ".",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"frameworksBackend": {
"region": "us-central1"
}
}
}
Then I run this command:
firebase deploy --only hosting
The commands works fine, But its the url is showing me this:
I want to know what i’m doing wrong here and why i’m not able to see the next.js application in that url.
I’ve tried to build and deploy the next.js application to firebase hosting but facing few errors.
I’m expecting to get the answer of my question from the experienced person.
2
Answers
A Next.js application needs to run code on the server, which requires the use of Cloud Functions. And since those won’t be deployed when you tell the Firebase CLI to deploy
--only hosting
, you end up seeing the default welcome page of Firebase Hosting.So run
firebase deploy
without options, orfirebase deploy --only hosting,functions
.You need to use functions if you need servver side code. If you only have a front-end and not using API routes, you can export static site.
For functions check out – https://github.com/vercel/next.js/tree/canary/examples/with-firebase-hosting
For static export, update
next.config.js
to includeoutput: 'export'