Serverless functions failing to build

Our volunteer developer created a web app for my nonprofit Altadena Rising (supporting Eaton Fire victims in Los Angeles), handed over the source code and then abruptly left the project. The app allows fire victims to share their stories and post them on a map of the town.

I am migrating his work from his Vercel environment to our Netlify environment. I got it up and running locally but I have not been able to deploy it using Netlify yet. I’m not a professional developer and have been using cursor & claude to work on this.

I am getting this build error:

8:09:58 PM: The following serverless functions failed to deploy: _@astrojs-ssr-adapter
8:09:58 PM: To deploy these functions successfully, change the function names to contain only alphanumeric characters, hyphens or underscores

I thought this was addressed by adding included_files = ["**/*"] to my netlify.toml:

[build]
base = "www"
command = "npm install && npm run build"
publish = "dist"
functions = ".netlify/build"

[[redirects]]
from = "/*"
to = "/.netlify/functions/entry"
status = 200

[dev]
framework = "astro"
targetPort = 4321

# Domain configuration
[context.production]
environment = { URL = "https://stories.altadenarising.org" }

[functions]
directory = ".netlify/build"
node_bundler = "esbuild"
external_node_modules = ["@astrojs/ssr"]
included_files = ["**/*"]

[build.environment]
NODE_VERSION = "18"

The “Why did it fail” AI failure analysis looks like an unrelated issue:.


Solution: To resolve this issue:

Verify if the package supporting the top-level await ('astro/env/setup') is included in the package.json or was committed to the repository.
Since top-level await is not supported with the 'cjs' output format, you may need to adjust the bundler configuration or the usage of top-level await in the code.
After addressing these points, trigger a new build to ensure the issue is resolved.

I believe that I already addressed this issue by following these steps:

**How to Implement ESM Configuration for Astro on Netlify**
Here's a brief explanation of how to implement Option 1 (updating your Astro configuration to use ESM):

1. Locate your Astro configuration file: Find your astro.config.mjs (or astro.config.js) file in your project's root directory.
2. Update the configuration: Modify your Astro config file to explicitly set the output format to ESM. You'll need to add Vite build options that specify ESM as the format.
3. Update Netlify configuration: Create or modify your netlify.toml file in the project root to ensure it supports ESM.
4. Verify Node.js version: Make sure your Netlify environment uses Node.js version 16 or higher (18+ recommended) to properly support ESM.
5. Update package.json: Check that your package.json has "type": "module" to indicate your project uses ESM.
6. Redeploy your application: Push your changes and redeploy on Netlify.
7. Check build logs: After deployment, check the Netlify build logs to confirm the error is resolved.

I appreciate any help. At this point I would be happy to pay someone to help us get this up and running becuase we have several people that want to add their stories about the fire.

Also, I could make the repo public if that helps. The code will be open sourced for other disaster victims once it’s functioning.

@Mauronic I don’t work with Astro, (or even host with Netlify), so can’t assist with your actual issue.

But just as a random tip, from what I can see, be aware that the netlify.toml (file based configuration) takes precedence over settings in the “Build settings” (those shown in the Netlify UI).

So if you’re using the netlify.toml you shouldn’t need to also set the values in the Netlify UI.

There’s no issue with what you have, since the values are the same, but just something to be aware of.

It’s addressed in the documentation here:
https://docs.netlify.com/configure-builds/file-based-configuration/


The error you’ve encountered is complaining about a function name containing characters other than “alphanumeric characters, hyphens or underscores”.

So I’d double check the names of the functions.

The included_files = ["**/*"] lets you specify additional files to be included in the functions bundle, (the documentation for it is here: https://docs.netlify.com/configure-builds/file-based-configuration/#functions), I wouldn’t expect it to circumvent any naming convention restrictions that may exist.

It may be that you don’t really want to “include everything” in the functions bundle.


I’m not sure what @astrojs/ssr (I can’t find much about it online), but you may want to look at the @astrojs/netlify adapter documentation here:
https://docs.astro.build/en/guides/integrations-guide/netlify/

1 Like

Hi, @Mauronic. I would encourage you to rely less on chatbots (and I personally loathe them) and to instead to make sure that you (not the bot) understand the messages you are reading. I say this because I believe if you parse this error message at the top of your first post, you will have the solution for this issue.

In other words, even as a non-developer or inexperienced developer, I think the error makes the solution clear if you examine it closely.

The error logged was this:

8:09:58 PM: The following serverless functions failed to deploy: _@astrojs-ssr-adapter
8:09:58 PM: To deploy these functions successfully, change the function names to contain only alphanumeric characters, hyphens or underscores

So, instead of telling what the solution is, let’s do a bit of rhetorical dialog.

Would you please answer these questions?

  1. What does the message say should be changed to deploy successfully?
  2. What are the requirements for function names? What characters can be in the name?
  3. What is the name of the function that is giving the error?
  4. Does that function meet the requirements for a function name? Does it contain characters which are not allowed? If so, which characters are not allowed?

I do not want you to wait for answers so I’ve included them in a block must be clicked to see below. That said, it might be a helpful thought experiment to try to answer the questions above yourself first.

Answers to the questions above (SPOILERS!)
  1. It says to “change the function names to contain only alphanumeric characters, hyphens or underscores”.
  2. The function name can only contain alphanumeric characters, hyphens or underscores.
  3. The name of the function is _@astrojs-ssr-adapter
  4. The function name contains the character @ which is not alphanumeric, a hyphen or an underscore.

If you remove that @ from the function name, it should resolve that error.

What follows is not related to your specific question. These are just some helpful docs about Astro sites on Netlify:

I don’t know that you need that documentation but it could be helpful so I thought I’d mention it.

Luke,

Thanks for the quick response. Please don’t assume that I am only relying on chatbots. I read the error message and answered all the questions you proposed before posting. “_@astrojs-ssr-adapter” does not exist in my codebase, perhaps it is generated during the build process?

I was hoping that there would be an obvious solution to this issue so I could get on with my life and launch this community site in time for a deadline.

If you have any ideas on what to poke at next, I am all ears.

p.s.

I hate chatbots too sometimes but I chuckled when you said not use rely on them because the output I shared came from Netlify’s own AI. Like I said, it seemed like a red herring.

@Mauronic It’s the error being encountered, so it’s not a ‘red herring’, it’s just unlikely to be the ‘root issue’.

So if it’s not in the codebase the questions (as you mention) become:

  • Where is it coming from?
  • Is it part of Netlify’s system (as you’ve asked)?
  • If so, is it supposed to be being submitted as a ‘function’ (or is something causing that to occur?)

The Netlify documentation for Astro is here:
https://docs.netlify.com/frameworks/astro/

It points to the @astro/netlify adapter as a requirement for using Astro’s SSR on Netlify.

You might want to run through that documentation, and just see how closely the project you’re submitting aligns with it.

As I previously pointed out, you might want to change that include_files definition too, if you can, to make it more specific and not “everything” (just in case it’s the source of issues).

1 Like

I checked the latest deploy: Deploy details | Deploys | altadenastories | Netlify and something has definitely changed by the time I got to this. The error message is now different.

I’d trim your netlify.toml to:

[build]
base = "www"
command = "npm run build"
publish = "dist"
[build.environment]
NODE_VERSION = "18"

[dev]
framework = "astro"
targetPort = 4321