Skip to content

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

@threepointone

Description

@threepointone

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions