@cypress/code-coverage Can't resolve '../self-coverage-helper' @cypress

1.5k Views Asked by At

I try to run in index.js of Cypress:

require('@cypress/code-coverage/task')

Getting this error:

Module not found: Error: Can't resolve '../self-coverage-helper' in 'C:\repo\patientstrength_codecover\node_modules\@cypress\code-coverage\node_modules\nyc'

Totally lost here. My package.json:

"nyc": "^15.1.0",
"cypress": "^5.0.0",
"cypress-istanbul": "^1.3.0",
"cypress-localstorage-commands": "^1.2.2",
"cypress-multi-reporters": "^1.2.4",
"@cypress/code-coverage": "^3.8.1",
"@babel/core": "^7.11.4",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-jsx": "^7.10.4",
"@babel/preset-env": "^7.11.0",
"@babel/preset-react": "^7.10.4",
1

There are 1 best solutions below

0
On

The issue was that we are using a "root" package.json with basic scripts like gulp, jest and well - also we tried to run Cypress from that root. And beside the coverage, it worked fine.

So we have:

  • /git/root/package.json
  • /git/root/solution1/package.json
  • /git/root/solution2/package.json

We solved the issue by simply install Cypress and all dependencies first (!) in the: /git/root/solution1/package.json and /git/root/solution2/package.json solutions.

NOT in the /git/root/package.json.

The /git/root/package.json now only contains a script invoking the 2 Cypress installations. And later we merge the results. Sure some redundancy

The invoke script is as following:

"test:client1": "cd client1 && cd ClientApp && npm run coverage"

So very simple approach. What we couldn't solve is the redundancy regarding Cypress configuration and commands. That can be optimized.