withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
43.87k stars 2.29k forks source link

import.meta.env.MODE and other related env variables don't get properly set in `astro build` #11282

Closed syhily closed 1 week ago

syhily commented 1 week ago

Astro Info

Astro                    v4.10.3
Node                     v22.3.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/mdx

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

No response

Describe the Bug

When I execute the astro build I found that the import.meta.env.MODE is always equal to the development. Even if I set the NODE_ENV=production.

I just add a console.log in astro.config.ts and you can easily check the different in the bellowing screenshots.

image image

What's the expected result?

The import.meta.env.MODE should be production when I execute the astro build.

Link to Minimal Reproducible Example

https://github.com/syhily/yufan.me

Participation

matthewp commented 1 week ago

Hi @syhily can you please create a reproduction using https://astro.new/latest . Debugging your personal website slows down our ability to discover and fix the problem. Thank you.

syhily commented 1 week ago

Sorry for the inconvenience. I only add two line of code on astro.config.ts and execute the astro build. I'm sure this could reproduce this issue 100%.

console.log(process.env.NODE_ENV);
console.log(import.meta.env.MODE);
github-actions[bot] commented 1 week ago

Hello @syhily. 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.