For context –
When deploying a Nuxt 3 site to Netlify with the build command pnpm build
, Netlify deploys a Nuxt app as an SSR app which runs on a function. This isn’t what I want to do.
When deploying a Nuxt 3 site to Netlify with the build command pnpm generate
, the Nuxt builder crawls the site, and pre-renders every route to static HTML, including any data pulled into the Nuxt app with API calls, and Netlify deploys that Nuxt app as a static generated app which is served as static files. This is what I want to do.
I’ve been struggling all day with trying to get Netlify functions working alongside a generated Nuxt app.
I’ve distilled the issue down to these files alongside my Nuxt app –
.nvmrc
containing v20.15.1
(I have tried this version of Node and a function in a separate project without Nuxt to make sure it’s not the issue)
package.json
containing these relevant parts
{
…
"engines": {
"node": "20.15.1",
"pnpm": "9.5.0"
},
"packageManager": "pnpm@9.5.0",
"scripts": {
…
"generate": "nuxt generate",
…
},
"dependencies": {
"@netlify/functions": "^2.8.1",
…
},
"devDependencies": {
"netlify-cli": "^17.33.4",
"nuxt": "^3.12.4",
…
}
}
/netlify/functions/test.mjs
containing just this
export default async (req, context) => {
console.log('Returning response');
return Response.json({
test: 'successful'
});
};
export const config = {
path: '/my-functions/test'
};
The Nuxt app works fine, apart from any areas which rely on Netlify functions.
When I visit https://my-obscured-nuxt-app.netlify.app/my-functions/test/
, I get a response with error 500.
When I visit the function log in the Netlify admin, I just see a spinning slash as if it’s still loading
\
…—
…/
…\
…—
…/
…
But when I run netlify dev
to run it locally… the function works!
You can probably tell that by now I’ve tried this with a few functions.
Can anyone please help me out? Is there something which Netlify is trying to do to be clever when it detects a Nuxt app which breaks functions when they’re in a site that has pnpm generate
as a build command? Has it been optimised for running an SSR server as a function and for edge functions, in such a way that it breaks compatibility with good old nuxt generate
?
Please save me. I’m running out of time and money to spend on this
If there’s anyone who can look at my site and use some admin-voodoo to find out what’s going on I’d be happy to privately share the details.
Edit:
You can actually just reproduce this as easily as
nvm use v20.15.1
corepack enable
corepack use pnpm@latest
pnpm dlx nuxi@latest init nuxt-with-netlify-functions-test
cd nuxt-with-netlify-functions-test/
pnpm add @netlify/functions
# add my function above^ to /netlify/functions/test.mjs
# push it to GitHub
# set it up on Netlify
# change the build command to `pnpm generate` or `pnpm run generate`
Which I’ve just done with a fresh repo etc to reproduce the issue myself.