Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'cypress', Cypress v10, cypress.config.js #423

Closed
andi1984 opened this issue Nov 18, 2022 · 3 comments
Closed

Cannot find module 'cypress', Cypress v10, cypress.config.js #423

andi1984 opened this issue Nov 18, 2022 · 3 comments

Comments

@andi1984
Copy link

Hi,

I am trying to run Cypress v10 within Browserstack using this CLI.

Our settings are:

  • browserstack-cypress-cli v1.19
  • Using cypress.config.js instead of older JSON schema
  • No Typescript needed

I took over the info from #342 (comment) that I need to specify cypress also in the npm_dependencies.

My browserstack.json config looks like this:

        "cypress_config_file": "./cypress.config.js",
        "cypress_version": "10",
        "project_name": "foo-cypress",
        "build_name": "foo-cypress-nightly",
        "exclude": [],
        "parallels": "1",
        "npm_dependencies": {
            "@badeball/cypress-cucumber-preprocessor": "^14.0.0",
            "@cypress/webpack-preprocessor": "^5.11.1",
            "cypress": "10",
            "js-yaml": "^4.1.0",
            "webpack": "^5.75.0"
        },
        "headless": true

but it fails in my CI process with the following traceback:

$ browserstack-cypress run --sync
[11/18/2022, 11:25:09 AM] - info: Reading config from /browsertests/browserstack.json
(node:16) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
[11/18/2022, 11:[25](jobs/3344815736#L25):09 AM] - error:  
{
  message: "Cannot find module 'cypress'\n" +
    'Require stack:\n' +
    '- /builds/browsertests/cypress.config.js\n' +
    '- /usr/local/lib/node_modules/browserstack-cypress-cli/bin/helpers/utils.js\n' +

My cypress.config.js looks like this:

const { defineConfig } = require('cypress');
const webpack = require('@cypress/webpack-preprocessor');
const preprocessor = require('@badeball/cypress-cucumber-preprocessor');

async function setupNodeEvents(on, config) {
    // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
    await preprocessor.addCucumberPreprocessorPlugin(on, config);
    ....

So it is pretty clear what the issue is: It can not find cypress within node modules resolution. Running Cypress locally works fine with the same config.

Any help would be appreciated what it could be. I also thought it might be how I specify the cypress versions within the browserstack.json. According to https://www.browserstack.com/docs/automate/cypress/supported-versions#supported-cypress-versions the latest might be either 10.3.0 or 10.8.0 (mentioned later on this page).

At this point I'm quite sure that the issue is most probably in this CLI, but I'm still not 100% sure.

What do you think? Anyone else here with the same issue? If someone runs Browserstack with Cypress 10 already it would be helpful to know which version of cypress you specified in the browserstack config and how your cypress.config.js looks like.

Thanks in advance,

Andi

@andi1984 andi1984 changed the title Cannot find module 'cypress' Cannot find module 'cypress', Cypress v10, cypress.config.js Nov 18, 2022
@sharutkarsh
Copy link

Hi Andreas,

I hope you are doing well.

I have read through your query and understood the issue.

Please try to install cypress on the CI env at the project level folder. This should solve the error.
The problem here is that you are importing cypress in its cypress.config.js file which can be done with cypress 10. At the CLI level, it read the cypress.config.js file for validations and tries to read projectId if the user forgot to mention the same in browserstack.json or passes it as a CLI arg.

The above-mentioned fix should solve the problem, otherwise please reach out to their technical support team.

I hope this helps.

Thanks!

@swatinigam
Copy link

Hi @sharutkarsh I have a similar question. We are using Cypress 12. The cypress config file has cypress import like so: import { defineConfig } from "cypress";

Our browserstack.json file clearly mentions the projectId. Do we still need to install Cypress in our CI environment? Is installing Cypress in our CI a prerequisite to browserstack-cypress package? It doesn't appear to be from this repo's readme, but would like to confirm.

Thank you for your help!

-Swati

@jdvegmond
Copy link

I've noticed that this issue disappears if you include 'cypress' as npm-dependency in browserstack.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants