Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare adapter no longer includes environment variables using "import.meta.env" @build #7137

Closed
1 task
davycoe opened this issue May 19, 2023 · 2 comments · Fixed by #7679
Closed
1 task
Labels
needs response Issue needs response from OP

Comments

@davycoe
Copy link

davycoe commented May 19, 2023

What version of astro are you using?

2.5.0

Are you using an SSR adapter? If so, which one?

Cloudflare 6.3.0

What package manager are you using?

npm

What operating system are you using?

Linux

What browser are you using?

Firefox

Describe the Bug

import.meta.env.MY_VAR is no longer defined at build time when deployed to Cloudflare.

Example I've included:

Deploy to Cloudflare and set the environment variables:

  • ENV_TEST_TWO = hello from process env!
  • VITE_ENV_TEST = hello from vite env!

Once set and deployed only the process.env.ENV_TEST_TWO will render.

If you trust that I didn't mess anything up you can see the result deployed here:
https://astro-cf-test.pages.dev/

I've added some config options to get this process.env to work:

import { defineConfig } from "astro/config";

import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: cloudflare(),
  vite: {
    define: {
      "process.env.ENV_TEST_TWO": JSON.stringify(process.env.ENV_TEST_TWO),
    },
  },
});

Is this expected/known?

Link to Minimal Reproducible Example

https://github.com/davycoe/astro_cf_test

Participation

  • I am willing to submit a pull request for this issue.
@alexanderniebuhr
Copy link
Member

I really do not want to link to another project here, but these discussions might share some light and even help for context:

t3-oss/t3-env#65
t3-oss/t3-env#60

@matthewp
Copy link
Contributor

You need to have the variable defined at build-time in order for it to be available at runtime. For example VITE_ENV_TEST='' astro build. It will still be pulled from runtime. Try that and let me know if it resolves the problem.

@matthewp matthewp added the needs response Issue needs response from OP label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs response Issue needs response from OP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants