currents-dev/cypress-cloud

Unable to load currents.config.js

Closed this issue · 4 comments

Before opening, please confirm:

  • I have searched for duplicate or closed issues and discussions.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I acknowledge that I will attach a full debug log, otherwise the issue will be closed with no response.

Environment information

# Put output below this line
  System:
    OS: macOS 13.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 23.83 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
  Browsers:
    Chrome: 111.0.5563.64
    Safari: 16.3
  npmPackages:
    @cypress/angular:  0.0.0-development 
    @cypress/mount-utils:  0.0.0-development 
    @cypress/react:  0.0.0-development 
    @cypress/react18:  0.0.0-development 
    @cypress/svelte:  0.0.0-development 
    @cypress/vue:  0.0.0-development 
    @cypress/vue2:  0.0.0-development 
    cypress: ^12.8.1 => 12.8.1 
    cypress-cloud: ^1.5.1 => 1.5.1 
  npmGlobalPackages:
    corepack: 0.10.0
    npm: 8.1.2
    yarn: 1.22.17

Describe the bug

Unable to load currents.config.js message displayed.

$ DEBUG=cypress:* node index.js
 WARNING  failed to load config file: /Users/xxxx/cypress-cloud-module-api/currents.config.js

file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/params.ts:81
    throw new ValidationError(projectIdError);
          ^
Error: Cannot resolve projectId. Please use one of the following:
- set CURRENTS_PROJECT_ID environment variable
- set "projectId" in "currents.config.js" file
- provide it as a "projectId" property for "run" API method
    at validateParams (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/params.ts:81:11)
    at run (file:///Users/xxxx/cypress-cloud-module-api/node_modules/lib/run.ts:20:27)
    at run2 (file:///Users/xxxx/cypress-cloud-module-api/node_modules/index.ts:13:10)
    at file:///Users/xxxxx/cypress-cloud-module-api/index.js:3:23
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at loadESM (node:internal/process/esm_loader:88:5)
    at handleMainPromise (node:internal/modules/run_main:65:12)

After adding projectId and recordKey to the run parameters,

$ DEBUG=cypress:* node index.js
 WARNING  failed to load config file: /Users/xxxxx/cypress-cloud-module-api/currents.config.js

file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/bootstrap/bootstrap.ts:20
  const cypressBin = await getBinPath(require.resolve("cypress"));
                                              ^
TypeError: __require.resolve is not a function
    at bootCypress (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/bootstrap/bootstrap.ts:20:47)
    at getMergedConfig (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/config.ts:66:19)
    at run (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/run.ts:34:18)
    at file:///Users/xxxxx/cypress-cloud-module-api/index.js:3:17

Expected behavior

Should be able to start Cypress with either currents.config.js or using parameters in run function

Command and Setup

clone https://github.com/lpanger/cypress-cloud-module-api

Then run:

yarn
node index.js

Full log and debug output

// Put your logs below this line
  currents:run run params { reporter: 'junit', browser: 'chrome', config: { baseUrl: 'http://localhost:8080', video: true } } +0ms
  currents:config loading currents config file from '/Users/xxxxx/cypress-cloud-module-api/currents.config.js' +0ms
 WARNING  failed to load config file: /Users/xxxxx/cypress-cloud-module-api/currents.config.js
  currents:config failure details: Error: Dynamic require of "/Users/xxxxx/cypress-cloud-module-api/currents.config.js" is not supported
    at file:///Users/xxxxx/cypress-cloud-module-api/node_modules/cypress-cloud/index.mjs:7:9
    at getCurrentsConfig (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/config.ts:43:22)
    at resolveCurrentsParams (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/params.ts:20:26)
    at validateParams (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/params.ts:76:18)
    at run (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/run.ts:20:27)
    at run2 (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/index.ts:13:10)
    at file:///Users/xxxxx/cypress-cloud-module-api/index.js:3:23
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at loadESM (node:internal/process/esm_loader:88:5)
    at handleMainPromise (node:internal/modules/run_main:65:12) +1ms
  currents:capture capturing stdout +0ms

When parameters are directly passed to run function

  currents:run run params { reporter: 'junit', browser: 'chrome', config: { baseUrl: 'http://localhost:8080', video: true }, projectId: 'blah', recordKey: 'key' } +0ms
  currents:config loading currents config file from '/Users/xxxxx/cypress-cloud-module-api/currents.config.js' +0ms
 WARNING  failed to load config file: /Users/xxxxx/cypress-cloud-module-api/currents.config.js
  currents:config failure details: Error: Dynamic require of "/Users/xxxxx/cypress-cloud-module-api/currents.config.js" is not supported
    at file:///Users/xxxxx/cypress-cloud-module-api/node_modules/cypress-cloud/index.mjs:7:9
    at getCurrentsConfig (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/config.ts:43:22)
    at resolveCurrentsParams (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/params.ts:20:26)
    at validateParams (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/params.ts:76:18)
    at run (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/run.ts:20:27)
    at run2 (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/index.ts:13:10)
    at file:///Users/xxxxx/cypress-cloud-module-api/index.js:3:23
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at loadESM (node:internal/process/esm_loader:88:5)
    at handleMainPromise (node:internal/modules/run_main:65:12) +0ms
  currents:validateParams validated currents parametes: { reporter: 'junit', browser: 'chrome', config: { baseUrl: 'http://localhost:8080', video: true }, projectId: 'blah', recordKey: 'key', cloudServiceUrl: 'https://cy.currents.dev', batchSize: 3, testingType: 'e2e' } +0ms
  currents:config resolving cypress config  +31ms
  currents:boot booting cypress... +0ms
  currents:capture capturing stdout +0ms

file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/bootstrap/bootstrap.ts:20
  const cypressBin = await getBinPath(require.resolve("cypress"));
                                              ^
TypeError: __require.resolve is not a function
    at bootCypress (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/bootstrap/bootstrap.ts:20:47)
    at getMergedConfig (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/config/config.ts:66:19)
    at run (file:///Users/xxxxx/cypress-cloud-module-api/node_modules/lib/run.ts:34:18)
    at file:///Users/xxxxx/cypress-cloud-module-api/index.js:3:17

@lpanger please fill in all the details

@lpanger you can switch to a CJS import , instead of ESM

Hey, @lpanger
Most of the problems you're facing are due to ESM quirks.

WARNING failed to load config file: /Users/xxxx/cypress-cloud-module-api/currents.config.js

Your example project has type: module and it cannot just import js files - e.g. currents.config.js
Removing type: module and renaming index.js to index.mjs should resolve the issue. The working example: https://github.com/currents-dev/cypress-cloud/actions/runs/4475641499/jobs/7865249524#step:10:1

TypeError: __require.resolve is not a function

Fixed in #99 and 1.5.2

My project needed type module but I was able to get everything working by passing parameters instead after the resolve fix. Thanks for the help