Background functions - $env/static/public could not be resolved

I’m running into some issues I’m hoping someone can help with.

I have a background function that I am developing in a SvelteKit project that needs to have access to environment variables. When running the code in my local Dev box through netlify-cli, I am getting the following error:

✘ [ERROR] Could not resolve "$env/static/public"
 
     src/lib/env/env_clientside.ts:1:106:
      1 │ ...EN, PUBLIC_S3_CLIENTSIDE_URL } from '$env/static/public';
         ╵                                         ~~~~~~~~~~~~~~~~~~~~
 
   You can mark the path "$env/static/public" as external to exclude it from the bundle, which will remove this error.

I know I can use process.env.XXX, but this background function resides in a SvelteKit project and re-uses a number of classes in that project that function just fine within non-background functions. What are people doing to get around this issue? I would hate to rewrite all code that uses SvelteKit’s $env/static/public due to this limitation.

I filed a bug report some time ago (Support for import.meta.env or $env/dynamic/private in Netlify background functions. · Issue #5286 · netlify/cli · GitHub), but I so far nobody has responded.

Thanks!

Hi @klomeli :wave:t6: ,

Welcome to the forums and thank you for reaching out! :netliconfetti: Which site are you referring to?

This is on a local instance running through netlify-cli. Want to resolve this before making a deployment. Any ideas when adding support for this will be looked at by the Dev team?

Thanks again!

To be clear, this is not a case of one env variable missing. This works fine if I use process.env.XXX. The problem arises when using SvelteKit’s recommended env variable support. This only affects background functions. Regular serverside functions work as expected.

Heya @klomeli!

I can guarantee you it has not been looked at by our developers yet since we have not yet escalated anything to them, since until today we were awaiting your response to proceed with our investigation. Now that you have responded, we’ll be happy to pick things up.

Mind filing an issue for us here? Issues · netlify/cli · GitHub

Let me know when you have, and I’ll ask the devs to take a look for us. Can’t make any promises on any timeline there (if the bug is even in our code, which may or may not be obvious to the authors), but I do promise to ask on our behalf :slight_smile:

Hi, yes. I posted one a couple of months ago. Here is a link:

Thanks for linking that issue! We’ll ask the team internally if this is on their radar or not and then we’ll let you know what we find.

It appears one of our devs has responded to your issue. Please follow-up there for any further discussions.