diff --git a/crates/next-core/src/env.rs b/crates/next-core/src/env.rs index d3bb86aaf6dcdf..392d1675ee7ad8 100644 --- a/crates/next-core/src/env.rs +++ b/crates/next-core/src/env.rs @@ -55,18 +55,20 @@ pub async fn env_for_js( } else { env }; - let env = EmbeddableProcessEnvVc::new(env).into(); - let image_config = next_config.image_config().await?; - let next_config = next_config.await?; + let env = + EmbeddableProcessEnvVc::new(CustomProcessEnvVc::new(env, next_config.env()).into()).into(); + let image_config = next_config.image_config().await?; let mut map = indexmap! { // We need to overload the __NEXT_IMAGE_OPTS to override the default remotePatterns field. // This allows us to support loading from remote hostnames until we properly support reading // the next.config.js file. - "__NEXT_IMAGE_OPTS".to_string() => serde_json::to_string(&image_config).unwrap(), + "__NEXT_IMAGE_OPTS".to_string() => serde_json::to_string(&image_config)?, }; + let next_config = next_config.await?; + if next_config.react_strict_mode.unwrap_or(false) { map.insert("__NEXT_STRICT_MODE".to_string(), "true".to_string()); } diff --git a/crates/next-core/src/next_config.rs b/crates/next-core/src/next_config.rs index a77fb20edb81ea..2c9bd948f5a154 100644 --- a/crates/next-core/src/next_config.rs +++ b/crates/next-core/src/next_config.rs @@ -1,5 +1,3 @@ -use std::collections::HashMap; - use anyhow::Result; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; @@ -8,6 +6,7 @@ use turbo_tasks::{ trace::TraceRawVcs, Value, }; +use turbo_tasks_env::EnvMapVc; use turbopack::{ evaluate_context::node_evaluate_asset_context, module_options::{ @@ -44,7 +43,7 @@ pub struct NextConfig { pub typescript: Option, pub react_strict_mode: Option, pub experimental: Option, - pub env: Option>, + pub env: IndexMap, pub compiler: Option, pub images: ImageConfig, pub transpile_packages: Option>, @@ -206,6 +205,11 @@ impl NextConfigVc { )) } + #[turbo_tasks::function] + pub async fn env(self) -> Result { + Ok(EnvMapVc::cell(self.await?.env.clone())) + } + #[turbo_tasks::function] pub async fn image_config(self) -> Result { Ok(self.await?.images.clone().cell())