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

--define without --minify does not replace process.env variables when accessed by index access instead of property access #16025

Open
aabccd021 opened this issue Dec 28, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@aabccd021
Copy link
Contributor

aabccd021 commented Dec 28, 2024

What version of Bun is running?

1.1.38+bf2f153f5

What platform is your computer?

Linux 6.6.63 x86_64 unknown

What steps can reproduce the bug?

// index.ts
if (process.env.LOREM === "lorem") {
  console.log("property access");
} 

if (process.env["LOREM"] === "lorem") {
  console.log("index access");
}
bun build --define process.env.LOREM="'lorem'" index.ts

What is the expected behavior?

// index.js
if (true) {
  console.log("property access");
}
if (true) {
  console.log("index access");
}

What do you see instead?

// index.js
if (true) {
  console.log("property access");
}
if (process.env["LOREM"] === "lorem") {
  console.log("index access");
}

Additional information

Might be related to #10165.

Users are required to do index access instead of property access on process.env if they enable noPropertyAccessFromIndexSignature tsconfig.json option.

It works fine when we add --minify flag.
It produces:

console.log("property access");console.log("index access");
@aabccd021 aabccd021 added bug Something isn't working needs triage labels Dec 28, 2024
@aabccd021 aabccd021 changed the title --define does not replace process.env variables when accessed by index access instead of property access --define without --minify does not replace process.env variables when accessed by index access instead of property access Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant