cypress-io/cypress-react-unit-test

Cannot find module node_modules/get-package-type/index (in nyc module)

anark opened this issue · 5 comments

anark commented

When I try to use the babelrc plugin in cypress

const preprocessor = require('cypress-react-unit-test/plugins/babelrc')

module.exports = (on, config) => {
  preprocessor(on, config)
  // IMPORTANT to return the config object
  // with the any changed environment variables
  return config
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
}

I get the error

**Message:** The function exported by the plugins file threw an error.

We invoked the function exported by `/Users/home/Development/project/cypress/plugins/index.js`, but it threw an error.

**Details:** Error: Cannot find module '/Users/home/Development/project/node_modules/get-package-type/index'
Require stack:
- /Users/home/Development/project/node_modules/nyc/index.js
- /Users/home/Development/project/node_modules/@cypress/code-coverage/task.js
- /Users/home/Development/project/node_modules/cypress-react-unit-test/plugins/babelrc/index.js
- /Users/home/Development/project/cypress/plugins/index.js
- /Users/home/Library/Caches/Cypress/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js
- /Users/home/Library/Caches/Cypress/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:961:15)
    at Function.Module._resolveFilename (/Users/home/Library/Caches/Cypress/5.4.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:844:27)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/home/Development/project/node_modules/nyc/index.js:23:24)
    at Module._compile (internal/modules/cjs/loader.js:1145:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
    at Module.load (internal/modules/cjs/loader.js:981:32)
    at Module._load (internal/modules/cjs/loader.js:881:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/home/Development/project/node_modules/@cypress/code-coverage/task.js:15:13)
    at Module._compile (internal/modules/cjs/loader.js:1145:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
    at Module.load (internal/modules/cjs/loader.js:981:32)
    at Module._load (internal/modules/cjs/loader.js:881:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:77:18)

**Stack trace:**
``
Error: The function exported by the plugins file threw an error.

We invoked the function exported by `/Users/home/Development/project/cypress/plugins/index.js`, but it threw an error.
    at Object.get (/Users/home/Library/Caches/Cypress/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/errors.js:968:15)
    at EventEmitter.<anonymous> (/Users/home/Library/Caches/Cypress/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/index.js:144:21)
    at EventEmitter.emit (events.js:310:20)
    at ChildProcess.<anonymous> (/Users/home/Library/Caches/Cypress/5.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:19:22)
    at ChildProcess.emit (events.js:310:20)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:85:21)

``

I get the same issue when adding the webpack loader via

    module.exports = (on, config) => {
      require('cypress-react-unit-test/plugins/load-webpack')(on, config)

       return config
    }
anark commented

It looks like the issue is that I have not setup code coverage. Is it a requirement to setup code coverage to use the webpack or babel loader?

This is weird, I will keep this open, but this is nyc not loading correctly, I have released cypress-react-unit-test@4.16.1 to only load nyc when needed, thus if you disable code coverage, then at least it does not crash

anark commented

Very strange, that seems to fix the first issue, however it still shows TypeError: (0 , _schemaUtils.validate) is not a function if you try to run the test.

I've updated cypres-react-unit-test in the example app to show that error if you try to run the spec.

anark commented

That fixes the terser issue.

Thanks!