Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

No cross-platform way of setting environment values containing spaces #248

Closed
ed-graham opened this issue Aug 17, 2020 · 1 comment
Closed

Comments

@ed-graham
Copy link

ed-graham commented Aug 17, 2020

  • cross-env version: 7.0.2
  • node version: 12.16.1
  • npm (or yarn) version: 6.13.4

Relevant code or config:

{
  "scripts": {
    "worksOnWin": "cross-env AUTHORIZER={\\\"claims\\\":{\\\"permissions\\\":\\\"\"[view:accounts manage:accounts]\"\\\",\\\"sub\\\":\\\"auth0|5cfe0adce3c4c50ea072ea9f\\\"}} AWS_PROFILE=elit_nonprd npm run env",
    "worksOnNix": "cross-env AUTHORIZER=\"{\\\"claims\\\":{\\\"permissions\\\":\\\"[view:accounts manage:accounts]\\\",\\\"sub\\\":\\\"auth0|5cfe0adce3c4c50ea072ea9f\\\"}}\" AWS_PROFILE=elit_nonprd npm run env",
}

What you did: I tried to create a single npm script that would set an environment variable called AUTHORIZER (needed when running an AWS Serverless app in offline mode) that took a value containing a space (here an array of permissions). The intended result is that the environment variable AUTHORIZER takes the following value:

{
  "claims":
  {
    "permissions": "[view:accounts manage:accounts]",
    "sub": "auth0|5cfe0adce3c4c50ea072ea9f"
  }
}

The best I could manage (with help from the Stack Overflow community) was the two platform-specific scripts above.

What happened: I failed to write a single script for both Windows and *Nix platforms and instead had to ditch cross-env altogether and resort to writing custom JavaScript code. See this issue on Stack Overflow. Trying to run the *Nix script on Windows gives the error The system cannot find the path specified..

Reproduction repository:

None.

Problem description:

There appears to be a bug in cross-env when setting environment variables that take values containing spaces.

Suggested solution:

None.

@kentcdodds
Copy link
Owner

#257

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

No branches or pull requests

2 participants