Skip to content

Cypress PowerShell: broken comma-separated-values CLI parsing since NodeJS 22.0.0 #6166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alexsch01 opened this issue Apr 30, 2025 · 10 comments

Comments

@alexsch01
Copy link
Contributor

alexsch01 commented Apr 30, 2025

PowerShell Command

npx cypress run --env a=1,b=2,c=3

Current behavior

{ a: '1 b=2 c=3' }

NodeJS 22.0.0 is different from older versions that it includes C:\Program Files\nodejs\npx.ps1 file

Desired behavior

{ a: 1, b: 2, c: 3 }

Test code to reproduce

cypress/e2e/spec.cy.js

it('', () => {
    cy.task('log', Cypress.env())
})

cypress.config.js

const { defineConfig } = require('cypress');

module.exports = defineConfig({
    e2e: {
        supportFile: false,
        screenshotOnRunFailure: false,
        setupNodeEvents(on) {
            on('task', {
                log(str) {
                    console.log(str)
                    return null;
                },
            });
        },
    },
});

Cypress Version

any (14.3.2 tested)

Node version

v22.0.0+ (v22.15.0 tested)

Operating System

Windows 10 22H2

Extra Information

  1. This issue affects --env and --config parsing
  2. Deleting C:\Program Files\nodejs\npx.ps1 is a workaround
@alexsch01 alexsch01 changed the title Cypress Powershell broken --env parsing since NodeJS 22.0.0 Cypress Powershell: broken --env parsing since NodeJS 22.0.0 Apr 30, 2025
@alexsch01 alexsch01 changed the title Cypress Powershell: broken --env parsing since NodeJS 22.0.0 Cypress Powershell: broken comma-separated-values CLI parsing since NodeJS 22.0.0 Apr 30, 2025
@alexsch01 alexsch01 changed the title Cypress Powershell: broken comma-separated-values CLI parsing since NodeJS 22.0.0 Cypress PowerShell: broken comma-separated-values CLI parsing since NodeJS 22.0.0 Apr 30, 2025
@MikeMcC399
Copy link
Contributor

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented May 1, 2025

@alexsch01
Copy link
Contributor Author

Not a duplicate because that specific issue no longer is reproducible on the newest Cypress version with NodeJS 16.18.1

I'm surprised nobody reported on this issue

@MikeMcC399
Copy link
Contributor

@alexsch01

Not a duplicate because that specific issue no longer is reproducible on the newest Cypress version with NodeJS 16.18.1

I changed it to "similar to ..." since the resolution was to enclose the option in quotes when using Windows PowerShell and this led to the addition of this instruction to the documentation.

The resolution of your issue would be to add quotes to your command in PowerShell:

npx cypress run --env "a=1,b=2,c=3"

You can see this also if you use cypress open, then view Settings -> Project settings -> Resolved configuration

Windows 11 24H2
Node.js 22.15.0
npm 10.9.2
PSVersion 5.1.26100.3912
Cypress 14.3.2

npx cypress open --e2e --browser electron --env "a=1,b=2,c=3"

Image

@jennifer-shehane
Copy link
Member

Perhaps we should update out docs to always recommend comments around the values?

@MikeMcC399
Copy link
Contributor

@jennifer-shehane

Perhaps we should update out docs to always recommend comments around the values?

Good point. The instructions are a little hidden on https://docs.cypress.io/app/references/environment-variables#Option-4---env and there is nothing on the https://docs.cypress.io/app/references/command-line about special requirements of PowerShell. I believe it is due to the comma character causing PowerShell to split out the parameters. Quoting the parameter stops PowerShell from attempting any further parsing.

This issue should probably go into https://github.com/cypress-io/cypress-documentation or a new one could be opened there.

@alexsch01
Copy link
Contributor Author

Ok I made a npm PR based on patch here npm/cli#8267

hopefully this could get backported to NodeJS 22 and NodeJS 24 at some point

@jennifer-shehane jennifer-shehane transferred this issue from cypress-io/cypress May 1, 2025
@jennifer-shehane
Copy link
Member

Moved issue to docs

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented May 2, 2025

@alexsch01

Thanks for finding the cli issue and following up with npm!

I suggest to wait for the resolution of the npm PR npm/cli#8267 before adding anything to the Cypress documentation, which already contains a hint in https://docs.cypress.io/app/references/environment-variables#Option-4---env

It looks like only PowerShell with npx for Node.js >=22 is affected. Running a script with npm, where the environment parameters are unquoted, works correctly

  "scripts": {
    "cy:env": "cypress run --env a=1,b=2"
  },
npm run cy:env
{ a: 1, b: 2 }

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented May 2, 2025

This issue also affects Yarn and pnpm running in Windows with PowerShell, so probably the npm PR will not fix all situations.

command result
npx cypress run --env a=1,b=2 incorrect
npm exec -c 'cypress run --env a=1,b=2' correct
npm run cy:env correct
yarn cypress run --env a=1,b=2 incorrect (Classic and Modern)
pnpm cypress run --env a=1,b=2 incorrect

For Yarn and pnpm the issue is also present with Node.js 20.

These PowerShell inconsistencies are not really something that Cypress can sort out. The pragmatic solution is to use quotes if necessary.

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

No branches or pull requests

3 participants