-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Current behavior
When running Cypress programmatically using the Module API (cypress.run()), Cypress fails during initialization with the following error:
TypeError: a.map is not a function
The error occurs before any tests execute, inside Cypress's internal buildBaseFullConfig logic (line ~2592:56060).
What works
- Cypress CLI execution (
npx cypress run) - Shell / bash scripts that invoke the Cypress CLI
What fails
- Programmatic execution via
require('cypress').run()
CLI execution completes successfully using the same configuration and test files.
Desired behavior
Programmatic execution via cypress.run() should behave the same as CLI execution and complete successfully without throwing a TypeError during configuration processing.
Test code to reproduce
Project structure
project-root/
├── cypress.config.ts
├── cypress/
│ ├── e2e/
│ │ └── test.cy.ts
│ └── fixtures/
│ └── environment.json
└── run-cypress.js
cypress.config.ts
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
baseUrl: 'https://example.com',
specPattern: 'cypress/e2e/**/*.cy.ts',
async setupNodeEvents(on, config) {
return config;
},
},
});cypress/e2e/test.cy.ts
// Top-level JSON import triggers the issue when using cypress.run()
import testData from '../../fixtures/environment.json';
describe('Test', () => {
it('should work', () => {
cy.visit('/');
});
});Note: The imported JSON does not need to be used; the presence of the import alone is sufficient to trigger the issue.
cypress/fixtures/environment.json
{
"production": {
"testUrls": []
}
}run-cypress.js
const cypress = require('cypress');
cypress
.run({
spec: ['cypress/e2e/test.cy.ts'],
headless: true,
browser: 'electron',
env: {
CYPRESS_NETWORK_THROTTLE: '4g-50mbps',
CYPRESS_TEST_ENV: 'production',
},
})
.then(results => console.log(results))
.catch(err => console.error(err));Run command
node run-cypress.jsExpected: Tests run successfully
Actual: Error occurs during initialization
Environment
- Cypress:
13.15.x,13.16.1,13.17.0,14.x,15.x - Node.js:
20.x LTS(also reproducible on22.x) - TypeScript:
5.9.3(withresolveJsonModule: true,module: "commonjs") - OS: macOS (Darwin 24.6.0)
- Package Manager: yarn
Debug Logs
TypeError: a.map is not a function
at D.buildBaseFullConfig (<embedded>:2592:56060)
at async D.getFullInitialConfig (<embedded>:2592:56822)
at async D.setupNodeEvents (<embedded>:2592:50907)
The error occurs during Cypress initialization, inside buildBaseFullConfig, before any test executes.
CLI execution works; programmatic execution fails.
Other
Additional context / analysis
- The error occurs during Cypress initialization, before any spec code executes
- The issue only appears when using the Module API (
cypress.run) - CLI execution follows a different internal initialization path and does not trigger the error
- The presence of a top-level JSON import in a spec file changes how Cypress resolves spec metadata
- During programmatic execution, this results in an internal value reaching
buildBaseFullConfigthat is not an array, leading to a.map()call on a non-array value
Attempted solutions
-
Cypress Module API (
cypress.run())- Passed config as a JavaScript object
- Used
specas both string and array formats - Avoided CLI argument parsing
Result: Error persists
-
Config simplification
- Minimal
cypress.config.ts - Removed all dynamic or conditional config
Result: Error persists
- Minimal
-
Config structure variations
- Tried
configFileoverride
Result: Error persists
- Tried
-
Version testing
- Cypress 13.x → 15.x
Result: Error persists across versions
- Cypress 13.x → 15.x
-
Environment isolation
- Validated JSON fixture contents before execution
Result: Error persists
- Validated JSON fixture contents before execution
-
Import attributes syntax
- Tested
import testData from '../../fixtures/environment.json' with { type: 'json' }; - TypeScript 5.9.3 supports import attributes (TypeScript 5.0+)
- Result: Error persists (same behavior as without
withsyntax) - Note: The
with { type: 'json' }syntax is required for pure Node.js ESM (Node.js ESM docs), but TypeScript withresolveJsonModule: truehandles JSON imports differently (TypeScript docs - note: does not mentionwithsyntax). Since CLI execution works with the current syntax, this suggests the issue is in Cypress's internal processing rather than the import syntax itself.
- Tested
Impact
- Blocks multi-run orchestration and CI/CD workflows that rely on programmatic execution
- Prevents Node.js-based Cypress runners from functioning
- Current workaround is invoking the Cypress CLI via shell scripts, which limits automation flexibility
Summary
Programmatic Cypress execution fails during internal config normalization when a spec contains a top-level JSON import.
CLI execution is unaffected, indicating a discrepancy between the CLI and Module API initialization paths.
Priority: High
Date: January 2026