Vercel-rust: too many environment variables

Error: Serverless Function runtime provided.al2023 does not support more than 4KB for environment variables

I get this error when trying to build my Rust project on the free tier in the cloud, but it works fine on my machine with vercel dev. I do not use environment variables at all, and I have disabled Automatically expose System Environment Variables.

vercel.json:

{
  "version": 2,
  "functions": {
    "api/**/*.rs": {
      "runtime": "vercel-rust@4.0.9"
    }
  }
}

Hey @rec-overflow, welcome! :waving_hand:

This happens because Vercel always includes system env vars, even if you’ve turned off “Automatically expose System Environment Variables.” The Rust runtime has a 4KB limit for env vars, and those system vars can push you over.

You can try updating to the latest Rust runtime instead of pinning to 4.0.9:

{ "version": 2, "functions": { "api/**/*.rs": { "runtime": "vercel-rust" } } }

Or switch to the Edge runtime which has different limits:

{ "version": 2, "functions": { "api/**/*.rs": { "runtime": "vercel-rust", "environment": "edge" } } }

Also double-check your project settings in the Vercel dashboard for any hidden env vars that may have been added automatically. If none of these help, you may need to restructure your functions or consider a different deployment approach.

Thank you for your answer!

Unfortunately, both changes result in an error:

Error: Function Runtimes must have a valid version, for example now-php@1.0.0.

and

Error: Invalid vercel.json - should NOT have additional property environment. Please remove it.

Running into the same issue, see Serverless Function runtime provided does not support more than 4KB for environment variables · Issue #183 · vercel-community/rust · GitHub

Also seeing this error for a project whose builds started failing out of the blue. Un-checking the “Automatically expose System Environment Variables” box does not work either.

I also started seeing these unexpectedly when a previous function was working correctly, now it is not. There might be something that the maintainers of the community run time can do.

I also wonder if Vercel intends to officially support a Rust runtime that has the same 64kb limit that other officially supported runtimes do.

This issue was solved some time ago, thanks to the report from this person

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.