Skip to content

Recommendation to set environment variable with special characters in name is misleading #827

Description

@alecglassford

In a few spots, docs/blog now recommend that you can set npm credentials using an environment variable1:

These recommend using the following syntax:

export "pnpm_config_//registry.npmjs.org/:_authToken=$NPM_TOKEN"

However, the above code snippet errors in bash or zsh (and I expect other shells), because they do not allow using setting environment variables with / or : or . in their name using this syntax.

Tangentially, the special characters in the environment variable name also seems to cause problems in GitHub Actions: pnpm/pnpm#12314 (comment)

While I think it is possible to set environment variables whose names have these characters using other tools (e.g. using the env utility or process.env in node), the fact that you can't do it with standard shell syntax makes the shell example in the docs kind of misleading and the feature hard to use in general.

Perhaps this caveat should be mentioned / the shell example should be removed / a more realistic example should be added. I think this might look like:

env "pnpm_config_//registry.npmjs.org/:_authToken=$NPM_TOKEN" pnpm install

(or, instead ofpnpm install, whatever pnpm command you want that uses auth)

Footnotes

  1. New feature from https://github.com/pnpm/pnpm/pull/12338

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions