Skip to content

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

Closed
@alexsch01

Description

@alexsch01
Contributor

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

Activity

changed the title [-]Cypress Powershell broken `--env` parsing since NodeJS 22.0.0[/-] [+]Cypress Powershell: broken `--env` parsing since NodeJS 22.0.0[/+] on Apr 30, 2025
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[/+] on Apr 30, 2025
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[/+] on Apr 30, 2025
MikeMcC399

MikeMcC399 commented on May 1, 2025

@MikeMcC399
Contributor
alexsch01

alexsch01 commented on May 1, 2025

@alexsch01
ContributorAuthor

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

MikeMcC399 commented on May 1, 2025

@MikeMcC399
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

jennifer-shehane commented on May 1, 2025

@jennifer-shehane
Member

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

MikeMcC399

MikeMcC399 commented on May 1, 2025

@MikeMcC399
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

alexsch01 commented on May 1, 2025

@alexsch01
ContributorAuthor

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 commented on May 1, 2025

@jennifer-shehane
Member

Moved issue to docs

MikeMcC399

MikeMcC399 commented on May 2, 2025

@MikeMcC399
Contributor

@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

MikeMcC399 commented on May 2, 2025

@MikeMcC399
Contributor

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.

MikeMcC399

MikeMcC399 commented on May 5, 2025

@MikeMcC399
Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jennifer-shehane@alexsch01@MikeMcC399

      Issue actions

        Cypress PowerShell: broken comma-separated-values CLI parsing since NodeJS 22.0.0 · Issue #6166 · cypress-io/cypress-documentation