cypress-docker-images icon indicating copy to clipboard operation
cypress-docker-images copied to clipboard

Error: Cannot find module 'fs-extra' in CI Pipeline

Open poponuts opened this issue 4 years ago • 5 comments

Current behavior

Cypress run fails in the CI pipeline as it looks for fs-extra plugin. Same command is used locally and works fine. The only difference is that CI relies on image: cypress/included:6.3.0. I use fs-extra as part of my plugin/index.js file.

The plugins file is missing or invalid.
Your `pluginsFile` is set to `/opt/atlassian/pipelines/agent/build/cypress/plugins/index.js`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js`, `.ts`, or `.coffee` file.
Or you might have renamed the extension of your `pluginsFile`. If that's the case, restart the test runner.
Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.
 Error: Cannot find module 'fs-extra'
Require stack:
- /opt/atlassian/pipelines/agent/build/cypress/plugins/index.js
- /root/.cache/Cypress/6.3.0/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js
- /root/.cache/Cypress/6.3.0/Cypress/resources/app/packages/server/lib/plugins/child/index.js

I have tried to re-install package-lock.json as there might be conflicts on versioning but still not working: https://stackoverflow.com/questions/63521764/cannot-find-module-fs-extra-error-when-launching-tests-despite-the-module-is-p

Desired behavior

Cypress should run successfully in the CI pipeline as it was working correctly before I upgraded the Cypress version and subsequently automatically updated the package-lock.json (Sorry, just blindly pushed it to master as it is a big file).

Test code to reproduce

Any repo will do but can be reproduced on a BITBUCKET PIPELINE. The following bitbucket-pipelines.yml file is what I have included in the root directory of any repo then understandably, run this if you have BITBUCKET PIPELINE account:

image: cypress/included:6.3.0
# image: cypress/base:14.15.0 <- used this previously and it worked but not when upgraded version to 6.3.0
options:
  max-time: 10

pipelines:
  default:
  - step:
      name: Install dependencies
      caches:
        - npm
      script:
        - npm ci
        - npx @bahmutov/print-env BITBUCKET # let's see the environment variables right away
        # - npm i fs-extra # TODO: still investigating why this is not installed automatically even if included in package.json
  - step:
      name: Run e2e tests
      caches: # not needed as taking it from the docker image
        - node
        - cypress
      script:
        # - npm run start:ci &
        - export PERCY_TOKEN=$PERCY_TOKEN # stored percy token as bitbucket pipeline variable
        - npx percy exec -- cypress run --env configFile=$HOST --spec cypress/tests/$TESTS # non-parallel tests
      artifacts:
        # store any generates images and videos as artifacts
        - cypress/screenshots/**
        - cypress/videos/**
        - cypress/test-reports/mocha/*.json
        - cypress/test-reports/*.xml
definitions:
  caches:
    npm: $HOME/.npm
    cypress: $HOME/.cache/Cypress

plugin/index.js

const fs = require('fs-extra')
const path = require('path')
let percyHealthCheck = require('@percy/cypress/task')

function getConfigurationByFile (file) {
    const pathToConfigFile = path.resolve('config', `${file}.env.json`)

    return fs.readJson(pathToConfigFile)
}

// plugins file
module.exports = async (on, config) => {
    // visual tests
    on('task', percyHealthCheck)

    const file = config.env.configFile || 'stage' // can be switched to other env (cypress run --env configFile=uat) or CI config
    config.file = await getConfigurationByFile(file)

    return config
}

Versions

Cypress version 6.3.0 CI Provider: Bitbucket pipeline (running on Bitbucket cloud agents) Note: I have installed fs-extra as dependency or devdependency manually and it only updated package.json and not package-lock.json as it seems Cypress already has the older versions of fs-extra. This approach did not work as well so to avoid conflict, I don't have fs-extra on my package.json now.

poponuts avatar Jan 20 '21 11:01 poponuts

I'm not sure how this is a Cypress issue. This seems to be an issue with your npm dependencies resolution.

If you are using fs-extra in your plugins file, you will need fs-extra as a dependency in your package.json have your package-lock.json up to date to the correct version and in version control.

This approach did not work as well so to avoid conflict, I don't have fs-extra on my package.json now.

I'm not sure what you mean by 'avoid conflict' in this situation.

jennifer-shehane avatar Jan 21 '21 04:01 jennifer-shehane

It could be our problem. We install cypress globally and I saw weird behavior with trying to locale any other NPM modules. But this issue probably better be moved to the cypress Docker images repo

Sent from my iPhone

On Jan 20, 2021, at 23:27, Jennifer Shehane [email protected] wrote:

 I'm not sure how this is a Cypress issue. This seems to be an issue with your npm dependencies resolution.

If you are using fs-extra in your plugins file, you will need fs-extra as a dependency in your package.json have your package-lock.json up to date to the correct version and in version control.

This approach did not work as well so to avoid conflict, I don't have fs-extra on my package.json now.

I'm not sure what you mean by 'avoid conflict' in this situation.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

bahmutov avatar Jan 21 '21 04:01 bahmutov

I've moved this to docker-images repo.

jennifer-shehane avatar Jan 21 '21 05:01 jennifer-shehane

I just ran into this using the latest Cypress docker runner. Maybe i'll need to extend the image to make sure fs-extra gets imported correctly.

djangofan avatar Aug 30 '21 18:08 djangofan

same issue here. was this solved?

Terkea avatar May 03 '22 09:05 Terkea