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

Using --define:process.env[\"SOME-TEST\"]=123 throws an error "Invalid identifier" #4008

Closed
threepointone opened this issue Dec 19, 2024 · 2 comments

Comments

@threepointone
Copy link

esbuild: playground url:
https://esbuild.github.io/try/#dAAwLjI0LjAALS1kZWZpbmU6cHJvY2Vzcy5lbnZbXCJTT01FLVRFU1RcIl09MTIzAGNvbnNvbGUubG9nKHByb2Nlc3MuZW52WyJTT01FLVRFU1QiXSk

There are some cases when using --define where identifiers need to be wrapped in quotes.

This is a minimal example of a case where this is needed.

npx esbuild --define:process.env[\\\"SOME-TEST-VAR\\\"]=123 test.js

(if you're using zsh, try this instead: npx esbuild --define:process.env\[\\\"SOME-TEST-VAR\\\"\]=123 test.js)

This will throw an error:

The define key "process.env[\"SOME-TEST-VAR\"]" contains invalid identifier "env[\"SOME-TEST-VAR\"]"

I've tried variations around quotes, but I can't get it to work. Am I doing something wrong, or is this a bug?

@evanw
Copy link
Owner

evanw commented Dec 19, 2024

Am I doing something wrong, or is this a bug?

Neither. This is a missing feature (but a reasonable one to add IMO). Support for these types of expressions has been added to --global-name but not yet to --define.

@evanw evanw closed this as completed in fd4cea7 Dec 19, 2024
@threepointone
Copy link
Author

Woah that's awesome that you already added the feature, thank you very much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants