Config Provider Initialization Order Issue with Layers

I have a lot of Layers, which yield some configs.
export const TelegramAdapterLive = Layer.effect(
    MessengerAdapter,
    Effect.gen(function* () {
        const botToken = yield* Config.redacted("TELEGRAM_BOT_TOKEN");
        const messageQueue = yield* Queue.unbounded<InputMessage>();
        const responseQueue = yield* Queue.unbounded<{userId: string, message: string}>();
        
        const bot = new Telegraf(Redacted.value(botToken));
        
        // Set up bot handlers
        bot.start((ctx) => {
            ctx.reply(TELEGRAM_MESSAGES.WELCOME);
        });
        
        bot.help((ctx) => {
            ctx.reply(TELEGRAM_MESSAGES.HELP);
        });
....


And when I assemble all my layers:
NodeRuntime.runMain(
    runApp().pipe(
        Effect.provide(MessageProcessorLayers),
        Effect.provide(MessengerAdapterLayer),
        // Effect.provide(TranslationLayers),
        Effect.provide(TranslationOmitLive),
        Effect.provide(TracerLive),
        Effect.withConfigProvider(
            ConfigProvider.fromJson(config).pipe(
                ConfigProvider.orElse(() => ConfigProvider.fromEnv()),
            ),
        ),
        Effect.provide(PlatformConfigProvider.layerDotEnvAdd('.env.local')),
        Effect.provide(NodeFileSystem.layer),
        Logger.withMinimumLogLevel(LogLevel.Debug),
        Effect.scoped
    )
)


I get errors saying that I did not pass some env variables, although they are in .env.local.
When I use dotenv lib, everything works fine. I guess that's how layers work, they are probably being bootstrapped before env variables are put in Config. So what's the correct way of doing this?
Was this page helpful?