diff --git a/.changeset/rude-falcons-smash.md b/.changeset/rude-falcons-smash.md new file mode 100644 index 000000000000..f27922395d47 --- /dev/null +++ b/.changeset/rude-falcons-smash.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Enable usage outside of vite contexts, such as the config file diff --git a/packages/integrations/image/src/lib/get-image.ts b/packages/integrations/image/src/lib/get-image.ts index 9ec58795bc19..c295831a345d 100644 --- a/packages/integrations/image/src/lib/get-image.ts +++ b/packages/integrations/image/src/lib/get-image.ts @@ -117,8 +117,9 @@ export async function getImage( const attributes = await loader.getImageAttributes(resolved); + // `.env` must be optional to support running in environments outside of `vite` (such as `astro.config`) // @ts-ignore - const isDev = import.meta.env.DEV; + const isDev = import.meta.env?.DEV; const isLocalImage = !isRemoteImage(resolved.src); const _loader = isDev && isLocalImage ? sharp : loader;