nitro icon indicating copy to clipboard operation
nitro copied to clipboard

v3: boolean in .env resolves to string

Open MickL opened this issue 3 weeks ago • 3 comments

Environment

Nitro: 3.0.1-alpha.1
Bun: 1.3.3

Reproduction

https://github.com/MickL/nitro-env-boolean

Describe the bug

I noticed that when using booleans in runtiemConfig it works:

export default defineConfig({
    serverDir: "./",
    runtimeConfig: {
        a: false,
        b: false,
    }
});

But when they get overwritten from .env they become a string:

.env

NITRO_B=false

handler

import {defineHandler} from "nitro/h3";
import {useRuntimeConfig} from "nitro/runtime-config";

export default defineHandler((event) => {
    const config = useRuntimeConfig();

    return {
        a: config.a, // boolean
        b: config.b, // string
    }
});

MickL avatar Dec 05 '25 13:12 MickL

.env variables are always interpreted as strings (FYI: https://nodejs.org/docs/latest/api/environment_variables.html#variable-values)

kricsleo avatar Dec 05 '25 16:12 kricsleo

I guess that depends on what library is used to parse the env file, some do parse to string, number, boolean, array.

Btw. I dont think the Node docs are a good reference since Node is more the exception than the standard.

MickL avatar Dec 05 '25 16:12 MickL

I guess that depends on what library is used to parse the env file

It's dotenv.

kricsleo avatar Dec 06 '25 09:12 kricsleo