cypress: react component testing: Cannot find get-package-type/index via nyc

Current behavior

When I run cypress run without using component testing, everything works fine. But when I add this line to my plugins/index.ts:

require("@cypress/react/plugins/load-webpack")(on, config);

I get the following error:

The function exported by the plugins file threw an error.

We invoked the function exported by `/Users/ahfarmer/dev/app/cypress/plugins/index.ts`, but it threw an error.

 Error: Cannot find module '/Users/ahfarmer/dev/app/node_modules/get-package-type/index'
Require stack:
- /Users/ahfarmer/dev/app/node_modules/nyc/index.js
- /Users/ahfarmer/dev/app/node_modules/@cypress/code-coverage/task.js
- /Users/ahfarmer/dev/app/node_modules/@cypress/react/plugins/load-webpack/index.js
- /Users/ahfarmer/dev/app/cypress/plugins/index.ts
- /Users/ahfarmer/Library/Caches/Cypress/6.1.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js
- /Users/ahfarmer/Library/Caches/Cypress/6.1.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:972:15)
    at Function.Module._resolveFilename (/Users/ahfarmer/Library/Caches/Cypress/6.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/tsconfig-paths/lib/register.js:71:48)
    at Module._load (internal/modules/cjs/loader.js:848:27)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12694)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/ahfarmer/dev/rhombus-repos/rhombus-cloud-frontend/web/node_modules/nyc/index.js:23:24)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Object.require.extensions.<computed> [as .js] (/Users/ahfarmer/Library/Caches/Cypress/6.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/ts-node/src/index.ts:529:44)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12694)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/ahfarmer/dev/rhombus-repos/rhombus-cloud-frontend/web/node_modules/@cypress/code-coverage/task.js:15:13)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Object.require.extensions.<computed> [as .js] (/Users/ahfarmer/Library/Caches/Cypress/6.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/ts-node/src/index.ts:529:44)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12694)

Test code to reproduce

I haven’t been able to isolate the problem yet. I’m not sure where to begin.

Versions

Tested with Cypress 6.0.0, 6.0.1 and 6.1.0 - all produce the same error.

More Info

It looks like this is related to code coverage. I’m not trying to use code coverage, but nyc is getting imported, and then it is trying to import get-package-type/index. The get-package-type module does exist in node_modules, but it is a .cjs file: node_modules/get-package-type/index.cjs. It seems like the Cypress loader is not looking for .cjs extensions in my particular scenario. I’m not sure why Cypress is normally able to find .cjs files but not in my particular case.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (13 by maintainers)

Most upvoted comments

@rockindahizzy I’m not working on my cypress project anymore, so I haven’t tested this with newer versions of Cypress.

🤔 will try look into this again.

I will try and verify that is true! I also would like code coverage to work. Having a work-around in place is good too, though, since we are rapidly iterating on component testing (stay tuned 😄)

I had this issue using the old cypress-react-unit-test package and it was fixed by dependency updates in that package.

I think 🤞 this https://github.com/cypress-io/cypress/pull/14165 recently merged PR along with setting coverage: false in your cypress.json should fix this