Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy next.js app on Firebase Hosting?

I am trying to deploy next.js app on Firebase hosting. But I don't understand which files to push to the server. When I run npm run build and pushed the build folder to firebase. But gives error that No index.html file found.

Here is the image of output of build folder. I have just created a simple component for testing purposes.

Output of build command

like image 895
Heir Of Knowledge Avatar asked May 24 '19 00:05

Heir Of Knowledge


People also ask

Can you use next JS with firebase?

To setup Firebase, use the following steps: First, go to the Firebase console and Add project. Enter the preferred name of your project, i.e., next-js-todos-app . Then click continue.

Where can I deploy my next JS app?

Next. js can be deployed to any hosting provider that supports Node. js. For example, AWS EC2 or a DigitalOcean Droplet.

Can firebase host node js app?

Firebase Hosting supports a REST API for advanced developers to build custom workflows, like deploying through a JavaScript app. We also have a Node. js module which you can import into your Node.

Can I deploy a next JS project to Firebase?

But that was not the case with Next.js Projects. This is because Next.js Application requires a server to handle server rendering. So deploying just static HTML is not sufficient. Here in this article, I will demonstrate the deployment of a Next.js project to the firebase platform using cloud Function and Firebase Hosting.

Why can’t I deploy static websites on Firebase?

Overview Deploying static websites like React Applications on the Firebase Platform is very straightforward. But that was not the case with Next.js Projects. This is because Next.js Application requires a server to handle server rendering. So deploying just static HTML is not sufficient.

What is Firebase Hosting and how do I use it?

With a single command, you can quickly deploy web apps and serve both static and dynamic content to a global CDN (content delivery network). You can also pair Firebase Hosting with Cloud Functions or Cloud Run to build and host microservices on Firebase. The modern web is secure.

What is Firebase N Ext JS used for?

With a single command, you can quickly deploy web apps and serve both static and dynamic content to a global CDN (content delivery network).“ — Firebase N ext.js is very awesome react framework to build applications, mostly preferred for its most useful feature, Server Side Rendering. It is very easy to learn and use for the react developers.


1 Answers

On package.json you need to add npm scripts for building and exporting like.

  "scripts": {     "dev": "next",     "build": "next build",     "start": "next start",     "export": "next export"   }, 

And then you can run

npm run build && npm run export 

Next build will build your project for shipping and export will put your files ready for hosting on a static hosting server (like firebase hosting).

npm run export 

will create an out/ directory and place all your files there ready for uploading.

Note:

If your app needs to generate dynamic pages at the runtime, you can't deploy it as a static app.

Read more

like image 149
ArchNoob Avatar answered Sep 22 '22 06:09

ArchNoob