Closed
Description
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
- This issue affects
--env
and--config
parsing - Deleting
C:\Program Files\nodejs\npx.ps1
is a workaround
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Cypress Powershell broken `--env` parsing since NodeJS 22.0.0[/-][+]Cypress Powershell: broken `--env` parsing since NodeJS 22.0.0[/+][-]Cypress Powershell: broken `--env` parsing since NodeJS 22.0.0[/-][+]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[/-][+]Cypress PowerShell: broken comma-separated-values CLI parsing since NodeJS 22.0.0[/+]MikeMcC399 commentedon May 1, 2025
@alexsch01
https://docs.cypress.io/app/references/environment-variables#Option-4---env
MikeMcC399 commentedon May 1, 2025
duplicatessimilar to issue CLI (env) options not correctly parsed cypress#27176alexsch01 commentedon May 1, 2025
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 commentedon May 1, 2025
@alexsch01
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 configurationWindows 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"
jennifer-shehane commentedon May 1, 2025
Perhaps we should update out docs to always recommend comments around the values?
MikeMcC399 commentedon May 1, 2025
@jennifer-shehane
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 commentedon May 1, 2025
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 commentedon May 1, 2025
Moved issue to docs
MikeMcC399 commentedon 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 onlyPowerShell with npx for Node.js >=22 is affected. Running a script with npm, where the environment parameters are unquoted, works correctlyMikeMcC399 commentedon 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.
npx cypress run --env a=1,b=2
npm exec -c 'cypress run --env a=1,b=2'
npm run cy:env
yarn cypress run --env a=1,b=2
pnpm cypress run --env a=1,b=2
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 commentedon May 5, 2025