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
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.
Next. js can be deployed to any hosting provider that supports Node. js. For example, AWS EC2 or a DigitalOcean Droplet.
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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With