withastro / adapters

Home for Astro's core maintained adapters
46 stars 25 forks source link

[EnvInvalidVariables] The following environment variables do not match the data type and/or properties defined in `experimental.env.schema`: #304

Closed lordor5 closed 1 week ago

lordor5 commented 1 week ago

Astro Info

Astro                    v4.11.1
Node                     v20.11.1
System                   Windows (x64)
Package Manager          bun
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             none

Describe the Bug

I'm getting the following error when a execute bun astro build && bun wrangler pages dev

[EnvInvalidVariables] The following environment variables do not match the data type and/or properties defined in experimental.env.schema: Variable PUBLIC_API_URL is not of type: string.

The error goes away when I set optional: true

  experimental: {
    env: {
      schema: {
        PUBLIC_API_URL: envField.string({
          context: "client",
          access: "public",
          startsWith: "http",
          optional: false,
        }),
      },
    },
  },

What's the expected result?

There shouldn't be an error

Link to Minimal Reproducible Example

https://github.com/lordor5/stllink2

Participation

lordor5 commented 1 week ago

I don't know why but astro will only read public variables in the .env file and private variables on the .dev.vars file. It wil not read variables from the wrangler.toml file. I created a branch in the minimal reproductible example called env were you can test it.

That may be why the page dosent works on cloudflare but it works localy if both files are present.

florian-lefebvre commented 1 week ago

If in 1 day I haven't followed up, feel free to ping me!

florian-lefebvre commented 1 week ago

Alright I checked and it's intended at this time:

alexanderniebuhr commented 6 days ago

@lordor5 I'm curious, why do you use bun astro build && bun wrangler pages dev instead of bun astro dev. Is there any reason or issue, we can improve astro dev?

lordor5 commented 6 days ago

Mainly because of env variables, I wasn't able to get them to work with bun astro dev. That's why I wanted to update to the latest astro version to use getSecret() and for now, with the new update of @astrojs/cloudflare@11 all env variables works perfectly, so I'm not needing wrangler pages dev. I haven't been able to use getSecret() for a D1 db, but I assume It's a lack of knowledge on my part.

florian-lefebvre commented 6 days ago

getSecret is not made for bindings

alexanderniebuhr commented 6 days ago

Interesting that astro dev didn't work for you.