cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.72k stars 3.16k forks source link

Your configFile is invalid: /builds/testverse/SwagLabs-Cypress/cypress.config.js #30242

Open Shady1997 opened 5 days ago

Shady1997 commented 5 days ago

Current behavior

Running cypress on gitlab pipeline show the following error:

$ npx cypress run --browser chrome --config-file cypress.config.js
It looks like this is your first time using Cypress: 13.14.2
[STARTED] Task without title.
[SUCCESS] Task without title.
Opening Cypress...
MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen
DevTools listening on ws://127.0.0.1:43023/devtools/browser/9b671992-2075-4b0c-b8b7-f2541d8c2980
Your configFile is invalid: /builds/testverse/SwagLabs-Cypress/cypress.config.js

It threw an error when required, check the stack trace below:

Error: Cannot find module 'cypress'
Require stack:
- /builds/testverse/SwagLabs-Cypress/cypress.config.js
- /root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js
- /root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/require_async_child.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Module._load (node:internal/modules/cjs/loader:1051:27)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/builds/testverse/SwagLabs-Cypress/cypress.config.js:2:26)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at loadFile (/root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:89:14)
    at EventEmitter.<anonymous> (/root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:116:38)
    at EventEmitter.emit (node:events:519:28)
    at process.<anonymous> (/root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:33:22)
    at process.emit (node:events:519:28)
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

Desired behavior

No response

Test code to reproduce

$ npx cypress run --browser chrome --config-file cypress.config.js
It looks like this is your first time using Cypress: 13.14.2
[STARTED] Task without title.
[SUCCESS] Task without title.
Opening Cypress...
MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen
DevTools listening on ws://127.0.0.1:43023/devtools/browser/9b671992-2075-4b0c-b8b7-f2541d8c2980
Your configFile is invalid: /builds/testverse/SwagLabs-Cypress/cypress.config.js
It threw an error when required, check the stack trace below:
Error: Cannot find module 'cypress'

Require stack:

- /builds/testverse/SwagLabs-Cypress/cypress.config.js
- /root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js
- /root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/require_async_child.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Module._load (node:internal/modules/cjs/loader:1051:27)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/builds/testverse/SwagLabs-Cypress/cypress.config.js:2:26)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at loadFile (/root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:89:14)
    at EventEmitter.<anonymous> (/root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:116:38)
    at EventEmitter.emit (node:events:519:28)
    at process.<anonymous> (/root/.cache/Cypress/13.14.2/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:33:22)
    at process.emit (node:events:519:28)
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

Cypress Version

cypress@13.14.2

Node version

20.17.0-1nodesource1

Operating System

ubuntu:latest

Debug Logs

No response

Other

No response

jennifer-shehane commented 3 days ago

@Shady1997 Is your config file invalid? You didn't share the contents of that file, so I can't be sure.

Shady1997 commented 3 days ago

@Shady1997 Is your config file invalid? You didn't share the contents of that file, so I can't be sure. this the config file:


// cypress.config.js
const { defineConfig } = require('cypress');

module.exports = defineConfig({ reporter: 'cypress-mochawesome-reporter', reporterOptions: { reportDir: 'cypress/reports', // Directory where the report will be saved charts: true, reportPageTitle: 'SwagLabs', videoOnFailOnly: true, saveAllAttempts: false, embeddedScreenshots: true, inlineAssets: true, overwrite: true, // Do not overwrite previous reports html: true, // Generate an HTML report json: false, // Optionally, also generate a JSON report timestamp: 'short', // Adds a timestamp to the report file name }, e2e: { baseUrl: 'https://www.saucedemo.com/v1/index.html', // Set your base URL video: true, // Enable video recording supportFile: false, // Disable support file if not needed specPattern: 'cypress/e2e/*/.js', // Adjust this to match your test files screenshotOnRunFailure: true, // Take screenshot on failure defaultCommandTimeout: 10000, // Increase timeout as needed setupNodeEvents(on, config) { // implement node event listeners here require('cypress-mochawesome-reporter/plugin')(on); }, }, });


and this the screenshot after list files to confirm config file included properly
![image](https://github.com/user-attachments/assets/77322b8a-d419-4a8f-b0ed-7a4998146838)
jennifer-shehane commented 3 days ago

@Shady1997 I think the problem here may be that cypress is not included in your package.json file. You cannot npx cypress run. You'll need to install cypress and run cypress run - this is why the cypress module isn't found.

Shady1997 commented 3 days ago

@Shady1997 I think the problem here may be that cypress is not included in your package.json file. You cannot npx cypress run. You'll need to install cypress and run cypress run - this is why the cypress module isn't found.

Please check this server error log: image

MikeMcC399 commented 1 day ago

@Shady1997

Your configFile is invalid:

It threw an error when required, check the stack trace below:

Error: Cannot find module 'cypress'

This is the error that you will get if cypress is missing from node_modules. Normally you would install Cypress locally with

npm install cypress --save-dev

and in .gitignore you would add

node_modules

Then you include the following files in your commit to the GitLab repo:

package.json
package-lock.json

Your workflow should include

npm ci

to install Cypress into your node_modules directory on GitLab temporarily.

See https://docs.cypress.io/guides/continuous-integration/gitlab-ci for GitLab examples.

For "how-to" type support you can connect to the Cypress technical community on Discord

Discord chat (click on button)

Your problem does not seem to be a bug in Cypress. It looks like a configuration error.