Getting Error: Cannot find module 'cypress-mochawesome-reporter/plugin' when i run cypress in docker

5.8k Views Asked by At

I have never used docker before. When I run it in my local it will be working fine but when I run using docker getting an error. I have created a docker file that contains the below line of code.

FROM cypress/base:14.19.0
RUN mkdir /legrande-cypress
WORKDIR /legrande-cypress
COPY ./package.json .
COPY ./cypress.json .
COPY ./cypress  ./cypress
RUN npm install
ENTRYPOINT ["npx","cypress","run"]

This is my package.json file.

{
  "name": "cypressautomation",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "delete:reportFolder": "rm -rf mochawesome-report/",
    "test:cli": "npm run delete:reportFolder && cypress run",
    "merge:reports": "mochawesome-merge mochawesome-report/*.json > cypress-combined-report.json",
    "create:html:report": "npm run merge:reports && marge --reportDir TestReport cypress-combined-report.json",
    "cy:run": "cypress run",
    "record-test": "cypress run --record --key ############################"
  },
  "reporter": "cypress-mochawesome-reporter",
  "reporterOptions": {
    "reportDir": "cypress/Reports",
    "charts": true,
    "reportPageTitle": "My Test Suite",
    "embeddedScreenshots": true,
    "inlineAssets": true
  },
  "video": false,
  "author": "weblylab",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^9.5.0",
    "cypress-file-upload": "^5.0.2",
    "cypress-mochawesome-reporter": "^2.2.0",
    "cypress-slack-reporter": "^1.2.1",
    "cypress-xpath": "^1.6.1",
    "faker": "^5.5.3",
    "i": "^0.3.6",
    "mocha": "^8.4.0",
    "mochawesome": "^6.2.2",
    "mochawesome-merge": "^4.2.0",
    "mochawesome-report-generator": "^5.2.0",
    "tsconfig-paths": "^3.9.0"
  },
  "dependencies": {
    "@auth0/auth0-spa-js": "^1.13.6",
    "@types/bluebird": "^3.5.33",
    "@types/lodash": "^4.14.168",
    "chai": "^4.3.0",
    "cypress-iframe": "^1.0.1",
    "cypress-skip-test": "^1.0.0",
    "delay": "^5.0.0",
    "Faker": "^0.7.2",
    "lodash": "^4.17.21",
    "moment": "^2.29.1",
    "resolve-url": "^0.2.1",
    "save": "^2.4.0",
    "source-map-resolve": "^0.6.0",
    "urix": "^0.1.0",
    "xlsx": "^0.17.0"
  }
}

When I run cypress test using docker run -i -v "%cd%":/legrande-cypress -t cypress-image:latest --spec cypress/integration/examples/*.js it will throwes an error below.

Your pluginsFile threw an error from: /legrande-cypress/cypress/plugins/index.js


Error: Cannot find module 'cypress-mochawesome-reporter/plugin'

Require stack:

- /legrande-cypress/cypress/plugins/index.js

- /root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js

- /root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/index.js

    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)

    at Function.Module._load (internal/modules/cjs/loader.js:746:27)

    at Module.require (internal/modules/cjs/loader.js:974:19)

    at require (internal/modules/cjs/helpers.js:101:18)

    at module.exports (/legrande-cypress/cypress/plugins/index.js:22:3)

    at /root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:94:12

    at tryCatcher (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)

    at Function.Promise.attempt.Promise.try (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)

    at load (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:91:7)

    at EventEmitter.<anonymous> (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:209:5)

    at EventEmitter.emit (events.js:400:28)

    at process.<anonymous> (/root/.cache/Cypress/9.5.1/Cypress/resources/app/packages/server/lib/plugins/util.js:19:22)

    at process.emit (events.js:400:28)

    at emit (internal/child_process.js:912:12)

    at processTicksAndRejections (internal/process/task_queues.js:83:21)

How to resolve this error please let me know if anyone has any idea.

0

There are 0 best solutions below