Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process.env and Bun.env have different results #15359

Closed
miruchigawa opened this issue Nov 23, 2024 · 4 comments
Closed

process.env and Bun.env have different results #15359

miruchigawa opened this issue Nov 23, 2024 · 4 comments
Labels
bug Something isn't working confirmed bug We can reproduce this issue

Comments

@miruchigawa
Copy link

What version of Bun is running?

1.1.36+ededc168c

What platform is your computer?

Linux 6.1.0-27-cloud-amd64 x86_64 unknown

What steps can reproduce the bug?

This bug was discovered when my RestAPI app displayed the development page. After investigating, we found that process.env.NODE_ENV always returned "development," regardless of what we tried to set—it always produced the same result.

What is the expected behavior?

Bun.env.NODE_ENV // production
process.env.NODE_ENV // production

What do you see instead?

Bun.env.NODE_ENV // production
process.env.NODE_ENV // development

Additional information

No response

@miruchigawa miruchigawa added bug Something isn't working needs triage labels Nov 23, 2024
@patrickdemers6
Copy link

Can you share a minimal reproduction? I'm not seeing this behavior.

// env.js
console.log("bun", Bun.env.NODE_ENV);
console.log("process", process.env.NODE_ENV);
$ NODE_ENV=production bun env.js
bun production
process production
$ NODE_ENV=development bun env.js
bun development
process development
$ bun -v
1.1.36

@miruchigawa
Copy link
Author

Maybe this issue comes during build?

***@***:~/Workspaces-Yuna/elysia-waifu$ bun run build
$ bun build src/index.ts --target bun --outdir ./build

  ./index.js 12750.55 KB

[630ms] bundle 811 modules
***@***:~/Workspaces-Yuna/elysia-waifu$ bun start
$ NODE_ENV=production bun build/index.js
Bun production
process development
import { $ } from 'bun';

export async function get_all_versions() {
    const v_bun = Bun.version;
    console.log("Bun", Bun.env.NODE_ENV)
    console.log("process", process.env.NODE_ENV)
    const v_rep = Bun.env.NODE_ENV !== 'production'
        ? 'Devel'
        : await $`git rev-parse --short HEAD`
            .then(r => r.text())
            .catch(_ => 'Unknown');

    return { v_bun, v_rep };
}

@RiskyMH
Copy link
Contributor

RiskyMH commented Nov 24, 2024

Maybe this issue comes during build?

I am pretty sure that's the issue. Bun build inlines process.env variables and as NODE_ENV defaults to development the issue is observed.

The solution should be for bun to not inline NODE_ENV (esp if not even defined), or even better don't inline process.env (#8125).

@RiskyMH RiskyMH added confirmed bug We can reproduce this issue and removed needs triage labels Nov 24, 2024
@miruchigawa
Copy link
Author

Okay, this case will be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue
Projects
None yet
Development

No branches or pull requests

3 participants