To deploy Nuxt on Netlify using the Node.js runtime instead of the Edge runtime, you need to make some configuration changes. Here's how you can do it:
- First, ensure you're using the correct Nitro preset for Netlify. In your
nuxt.config.ts file, add the following:
export default defineNuxtConfig({
nitro: {
preset: 'node-server'
}
})
This sets the preset to node-server, which is suitable for Node.js environments Docs > Getting-started > Deployment (https://nuxt.com/docs/getting-started/deployment#nodejs-server).
- Create a
netlify.toml file in the root of your project with the following content:
[build]
command = "npm run build"
publish = "dist"
[functions]
directory = ".output/server"
[[redirects]]
from = "/*"
to = "/.netlify/functions/server"
status = 200
This configuration tells Netlify to use the Node.js functions for serving your Nuxt application Docs > Getting-started > Deployment (https://nuxt.com/docs/getting-started/deployment#nodejs-server).
- Make sure your
package.json has the correct build and start scripts:
{
"scripts": {
"build": "nuxt build",
"start": "node .output/server/index.mjs"
}
}
-
When deploying, make sure to set the Node.js version in your Netlify dashboard or by adding a .nvmrc file to your project with the desired Node.js version.
-
Deploy your application to Netlify. The build command will generate the necessary files, and Netlify will serve your Nuxt application using Node.js functions.
By following these steps, you'll deploy your Nuxt application on Netlify using the Node.js runtime instead of the Edge runtime. This approach uses Netlify Functions to run your Nuxt server-side code.