Nx: `nx e2e` with Cypress triggers `Unknown option: '--env'`

Created on 20 Aug 2020  路  8Comments  路  Source: nrwl/nx

Current Behavior

The --env flag is not recognized by the nx e2e command.

Expected Behavior

I would like to be able to use an --env flag to specify custom variables for Cypress on the command line, as we can do with the cypress run command.

Steps to Reproduce

  • Create an app with Cypress e2e capability named 'my-app'.
  • Add the environment variable declaration in apps/my-app-e2e/cypress.json:
{
    "env": {
        "myEnvKey": "myEnvDefaultValue"
    },
    "fileServerFolder": ".",
    "fixturesFolder": "./src/fixtures",
    "integrationFolder": "./src/integration",
    "modifyObstructiveCode": false,
    "pluginsFile": "./src/plugins/index",
    "supportFile": "./src/support/index.ts",
    "video": true,
    "videosFolder": "../../dist/cypress/apps/my-app-e2e/videos",
    "screenshotsFolder": "../../dist/cypress/apps/my-app-e2e/screenshots",
    "chromeWebSecurity": false
}
$> yarn run nx e2e --project=my-app-e2e --env.myEnvKey myEnvValue

yarn run v1.21.1
$ nx e2e --project=my-app-e2e --env.myEnvKey foo

> ng run my-app-e2e:e2e --env=[object Object] 
Unknown option: '--env'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Failure Logs

Unknown option: '--env'

Environment

$> yarn run nx report

yarn run v1.21.1
$ nx report

>  NX  Report complete - copy this into the issue template

  nx : Not Found
  @nrwl/angular : 10.0.13
  @nrwl/cli : 10.0.10
  @nrwl/cypress : 10.0.10
  @nrwl/eslint-plugin-nx : 10.0.10
  @nrwl/express : Not Found
  @nrwl/jest : 10.0.10
  @nrwl/linter : Not Found
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 10.0.10
  @nrwl/web : Not Found
  @nrwl/workspace : 10.0.10
  typescript : 3.9.7

Done in 2.35s.

Other information

  • There was an issue about it in the past: #1970
testing tools bug

Most helpful comment

@hadrien-toma @mehrad-rafigh I think this is related to the way we parse the extra arguments. I have a PR open already to fix the arrays, but I will change it to a more generic approach so we can avoid such issues in the future. Stay tuned 馃槃

All 8 comments

Experienced the same issue. I will open a PR later today!

@hadrien-toma @mehrad-rafigh I think this is related to the way we parse the extra arguments. I have a PR open already to fix the arrays, but I will change it to a more generic approach so we can avoid such issues in the future. Stay tuned 馃槃

@hadrien-toma my PR solves the issue of --env=[object Object] but even then I get this error for ng:

yarn run nx e2e --project=my-app-e2e --env.myEnvKey myEnvValue

> ng run my-app-e2e:e2e --env.myEnvKey myEnvValue 
Unknown option: '--env.myEnvKey'
Unknown option: 'myEnvValue'
error Command failed with exit code 1.

Have to investigate it more!

@bekos Ah sorry, I think the correct command should in fact be: --env myEnvKey=myEnvValue like in the Cypress documentation. Thank you very much for the help!

@hadrien-toma my PR solves the issue of --env=[object Object] but even then I get this error for ng:

yarn run nx e2e --project=my-app-e2e --env.myEnvKey myEnvValue

> ng run my-app-e2e:e2e --env.myEnvKey myEnvValue 
Unknown option: '--env.myEnvKey'
Unknown option: 'myEnvValue'
error Command failed with exit code 1.

Have to investigate it more!

Hi. How does it fix your problem?? #2 used to work for me, 20 odd days back. What changed now ?

1 -

PS C:\Workspaces\git\kiosk-react> nx custom myProject --env build=PR-122

nx run myProject :custom --env=build=PR-122
Schema validation failed with the following errors:
Data path ".env" should be object.

Or.

2 -

PS C:\Workspaces\git\kiosk-react> nx custom myProject --env.build PR-122

nx run myProject :custom --env=[object Object]
Schema validation failed with the following errors:
Data path ".env" should be object.

@panraj01 As you see that PR was merged 10 days ago, so it is not released yet. What version of Nx are you using?

@bekos - I am on 9.3.0. Any idea on what release version it is targeted and time of release ? In the interim, is there a way to get it to work, i know for sure, this has worked for me in the past: How do i get this to work while your release is in flight?

PS C:\Workspaces\git\kiosk-react> nx custom myApp-e2e --env.build PR-122

nx run myApp-e2e:custom --env=[object Object]
Schema validation failed with the following errors:
Data path ".env" should be object.

This is driving me nuts. It worked yesterday, its not working today again.

nx custom app-name-e2e --env.build 1.1.79 --watch
Schema validation failed with the following errors:
Data path ".env" should be object.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kmkatsma picture kmkatsma  路  3Comments

elliotmendiola picture elliotmendiola  路  3Comments

about-code picture about-code  路  3Comments

joelmuskwe picture joelmuskwe  路  3Comments

Koslun picture Koslun  路  3Comments