Unable to run a function alongside a generated Nuxt app

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 :sob:

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.

Please let us know the site name.

Hey @hrishikesh - Thanks for replying so quickly!

You can have a look at this site I made to reproduce the problem.

https://nuxt-with-netlify-functions-temp-test.netlify.app/my-functions/test

I think this is some weird error on our end. Based on what I can see, you seem to have everything setup correctly, but based on some internal logs, this looks like a failure on our end. Sorry about that, I’ve asked the devs to take a look.

Thanks for taking the time to look into it!

Can I DM you the other site which I’ve been using where I found this please? I need to keep it private as it has a client’s details on it.

Sure, feel free to DM.

I can’t find a link to do that anywhere - is it enabled on the board?

Do you maybe have an email instead?

Edit: Maybe you can find it from my account, it’s the other site I’ve been deploying to over the last couple of days that’s three kebab case words ending in -website-nuxt

I have enabled DMs for your account.

But, I found the site you mentioned and it’s facing the same issue. I have no idea why that is, I have not seen that error message before.

For the time being, could you try deploying Functions on a separate (non-Nuxt) site? And you can use those Functions on your original site till we get this sorted.

That’s a great idea, thanks :slightly_smiling_face:

I’m just glad that you’ve verified the issue at this point, I’ve been going round in circles all day.

My guess is someone has configured some kind of auto-magic build step to make Nuxt’s newer features zero-config, but not looked at compatibility with what I suppose is now an edge case that was once one of their flagship features.

Have you been given any kind of indication as to whether it might be fixed soon or if it’s maybe pretty far down the backlog?

The issue has been identified and we’re working on it. Though there’s no definite timeline yet. The team is currently navigating though various other issues as well, so this might take some time.

You have 2 additional workarounds:

  • remove the /* /404.html 404 redirect which is possibly generated by Nuxt
  • or delete the 404.html that gets generated

I wouldn’t have guessed that file was causing it!

Will you update here once it’s been fixed, or is there somewhere else I can look for release notes?

Sure, I’ll reply here.

Awesome! Thanks man, I really appreciate it :slight_smile:

@hrishikesh has there been any progress on this?

Not much. It’s a low-priority backlog issue, so I don’t expect any immediate changes.