withastro / adapters

Home for Astro's core maintained adapters
64 stars 33 forks source link

Bug Report: Unable to Destructure 'env' Property from 'Astro2.locals.runtime' #287

Closed lowintechie closed 3 months ago

lowintechie commented 3 months ago

Astro Info

yarn dev

 ⛅️ wrangler 3.60.2
-------------------

interface Env {
        MY_VARIABLE: "test";
        DB_PASSWORD: string;
}

02:08:23 [WARN] [config] The feature "astro:env getSecret" is experimental and subject to change (used by @astrojs/cloudflare).
02:08:23 [types] Added src/env.d.ts type declarations.

 astro  v4.10.2 ready in 2534 ms

┃ Local    http://localhost:8002/
┃ Network  http://XXXXXXXXX:8002/

02:08:24 watching for file changes...
02:08:42 [ERROR] Cannot destructure property 'env' of 'Astro2.locals.runtime' as it is undefined.

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When attempting to destructure the 'env' property from the 'Astro2.locals.runtime' object, an error occurs stating that the property is undefined. This prevents the expected behavior of the code and hinders its functionality.

What's the expected result?

The 'env' property should be properly defined within the 'Astro2.locals.runtime' object and should be successfully destructured without encountering any errors.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-4gxv2t?file=src%2Fpages%2Findex.astro

Participation

ematipico commented 3 months ago

Please update the template and provide the information of astro info.

Please provide a valid reproduction. Your reproduction doesn't have a middleware, where you should populate your runtime object.

github-actions[bot] commented 3 months ago

Hello @lowinn. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

lowintechie commented 3 months ago

Please update the template and provide the information of astro info.

Please provide a valid reproduction. Your reproduction doesn't have a middleware, where you should populate your runtime object.

I already updated please check

ematipico commented 3 months ago

@lowinn the reproduction is incorrect, because you aren't creating any runtime object

Where do you expect to get that value? Have you read some documentation somewhere? Please share as much information as possible, because I am not really sure what you're doing.

lowintechie commented 3 months ago

@lowinn the reproduction is incorrect, because you are creating any runtime object

Where do you expect to get that value? Have you read some documentation somewhere? Please share as much information as possible, because I am really sure what you're doing.

Hello @ematipico , allow me to clarify my current situation. I'm new to astro, having started exploring it just a week ago. I've begun a project and have been attempting to configure various aspects using the provided documentation. However, I've encountered an error within the section linked here: https://docs.astro.build/en/guides/integrations-guide/cloudflare/#cloudflare-runtime

I'm unsure how to provide more information to assist you in helping me resolve this issue quickly. Could you suggest where else I might look for a solution?

ematipico commented 3 months ago

Ah, I see. You haven't installed the Cloudflare adapter:)

lowintechie commented 3 months ago

Ah, I see. You haven't installed the Cloudflare adapter:)

image

I'm done

OliverSpeir commented 3 months ago
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: cloudflare()
});

is needed to actually enable the cloudflare adapter

lowintechie commented 3 months ago
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: cloudflare()
});

is needed to actually enable the cloudflare adapter

I already added dear @OliverSpeir

OliverSpeir commented 3 months ago

Ah I didn't see that in the stackblitz, so the issue persists?

Can you give exact steps to recreate with a repo? I'm assuming the stackblitz won't work due to needing to use wrangler dev

Thanks for your patience, we appreciate you taking the time to sort this out

lowintechie commented 3 months ago

Ah I didn't see that in the stackblitz, so the issue persists?

Can you give exact steps to recreate with a repo? I'm assuming the stackblitz won't work due to needing to use wrangler dev

Thanks for your patience, we appreciate you taking the time to sort this out

@OliverSpeir You can check here : https://stackblitz.com/edit/withastro-astro-babntn?file=src%2Fpages%2Findex.astro

alexanderniebuhr commented 3 months ago

@lowinn you need to enable the support for astro dev manually. It will be enabled by default with the next major version.

import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
  output: 'server',
+  adapter: cloudflare({
+    platformProxy: {
+      enabled: true
+    }
+  }),
});
lowintechie commented 3 months ago

@lowinn you need to enable the support for astro dev manually. It will be enabled by default with the next major version.

import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
  output: 'server',
+  adapter: cloudflare({
+    platformProxy: {
+      enabled: true
+    }
+  }),
});

@alexanderniebuhr @ematipico @OliverSpeir Thank you guys it's work now.