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

cross-env version 5.0.0 no longer seems to replace environment variables #125

Closed
derekgreer opened this issue Jul 19, 2017 · 5 comments
Closed

Comments

@derekgreer
Copy link

I'm running bash on windows. After upgrading from cross-env 4.0.0 to 5.0.0, environment variables don't seem to be replaced the same way.

This works:

{                                                                                   
  "name": "testapp",                                                                
  "version": "1.0.0",                                                               
  "license": "MIT",                                                                 
  "config": {                                                                       
    "environment": "localhost"                                                      
  },                                                                                
  "scripts": {                                                                      
    "echo": "cross-env echo ${npm_package_config_environment} ${test}"              
  },                                                                                
  "devDependencies": {                                                              
    "cross-env": "^4.0.0"                                                           
  }                                                                                 
}  
$> test=xxx npm run echo

> exports@1.0.0 echo C:\Temp\npmtest
> cross-env echo ${npm_package_config_environment} ${test}

localhost xxx

This does not work:

{                                                                                   
  "name": "testapp",                                                                
  "version": "1.0.0",                                                               
  "license": "MIT",                                                                 
  "config": {                                                                       
    "environment": "localhost"                                                      
  },                                                                                
  "scripts": {                                                                      
    "echo": "cross-env echo ${npm_package_config_environment} ${test}"              
  },                                                                                
  "devDependencies": {                                                              
    "cross-env": "^5.0.0"                                                           
  }                                                                                 
} 
$> test=xxx npm run echo

> exports@1.0.0 echo C:\Temp\npmtest
> cross-env echo ${npm_package_config_environment} ${test}

%npm_package_config_environment% %test%
@kentcdodds
Copy link
Owner

Hi 👋

Please use cross-env-shell for this. See the README. 👍

Good luck!

@derekgreer
Copy link
Author

Thanks for pointing me to cross-env-shell. FWIW, I read the README and saw that there was a new cross-env-shell command prior to opening this issue, but the description didn't seem to match my usage scenario and so it wasn't immediately clear it could be used in this way. For example, the README states:

The main use case for cross-env-shell is when your need an environment variable to be set across an entire inline shell script, rather than just one command.

Since I was only using a single command in my example (i.e. "echo") and was trying to substitute environment variables set for the process running npm rather than an individual script command, the description and example provided didn't seem to match my usage scenario.

Perhaps it would be beneficial to show an example of the command's use with environment variables set for the npm process rather than for a single script entry:

{
  "scripts": {
    "greet": "npm-run-all greet:*",
    "greet:english": "cross-env-shell echo Hello, $NAME!",
    "greet:spanish": "cross-env-shell echo ¡Hola, $NAME!",
    "greet:french": "cross-env-shell echo Bonjour, $NAME!"
  }
}

$> NAME=Bob npm run greet

@kentcdodds
Copy link
Owner

Agreed. Thanks @derekgreer. Could you file a PR to update the README?

@derekgreer
Copy link
Author

Sure.

@parkerault
Copy link

parkerault commented Jul 18, 2019

I'm having a similar issue trying to use command substitution. It works in linux, but not windows.

{
  "scripts": {
    "start": "cross-env-shell COMMIT_HASH=$(git show --no-patch --format=%h) react-scripts start",
  }
}

It fails with "react-scripts was unexpected at this time" using both cross-env-shell and cross-env. Am I doing something wrong here?

Edit: I figured it out: #192 (comment)

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

3 participants