Using `--define:process.env[\"SOME-TEST\"]=123` throws an error "Invalid identifier"
Closed this issue · 2 comments
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?
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
.
Woah that's awesome that you already added the feature, thank you very much!!