Closed aksyuma closed 5 months ago
Please create a repo with the problem and steps to reproduce the issue so I can have a look.
Thanks.
Hi @LironEr / @syumaK -
I encountered this error (or something similar) in the process of upgrading my repository from Cypress 12.1.0
to 13.6.0
. As best as I can tell, this issue is caused by upgrading to Node 14+ and setting type: module
in your package.json
. This changes the compilation type to ES6 and causes compatibility issues.
Here's how I encountered this issue:
npm-check-updates -u
plugins/index.js
file and insert in defineConfig
within cypress.config.js
package.json
to include type: module
to specify ES6 compilation.cypress.config.js
to ES6-style imports.This causes the error reported above:
ReferenceError: require is not defined
at setupNodeEvents (file:///C:/Users/XXX/testing/cypress.config.js:49:25)
My first attempt was to monkey-patch require
via importing createRequire
from module
as suggested in this SO post. This did not work for me, and instead, produced a rather cryptic error:
TypeError [undefined]: The "id" argument must be of type string. Received function registerChildEvent
at new NodeError (node:internal/errors:399:5)
at validateString (node:internal/validators:163:11)
at Module.require (node:internal/modules/cjs/loader:1134:3)
at require (node:internal/modules/cjs/helpers:110:18)
at setupNodeEvents (file:///C:/Users/XXX/testing/cypress.config.js:49:90)
Now, on to the resolution:
cypress-mochawesome-reporter/plugin
module as an ES6 import:import plugin from 'cypress-mochawesome-reporter/plugin';
require('cypress-mochawesome-reporter/plugin')( on )
line to plugin( on )
Cypress should load the plugin correctly.
Hopefully this helps!
Hi @LironEr / @syumaK -
I encountered this error (or something similar) in the process of upgrading my repository from Cypress
12.1.0
to13.6.0
. As best as I can tell, this issue is caused by upgrading to Node 14+ and settingtype: module
in yourpackage.json
. This changes the compilation type to ES6 and causes compatibility issues.Here's how I encountered this issue:
npm-check-updates -u
- Extracted configuration from
plugins/index.js
file and insert indefineConfig
withincypress.config.js
- Updated
package.json
to includetype: module
to specify ES6 compilation.- Updated imports within
cypress.config.js
to ES6-style imports.This causes the error reported above:
ReferenceError: require is not defined at setupNodeEvents (file:///C:/Users/XXX/testing/cypress.config.js:49:25)
My first attempt was to monkey-patch
require
via importingcreateRequire
frommodule
as suggested in this SO post. This did not work for me, and instead, produced a rather cryptic error:TypeError [undefined]: The "id" argument must be of type string. Received function registerChildEvent at new NodeError (node:internal/errors:399:5) at validateString (node:internal/validators:163:11) at Module.require (node:internal/modules/cjs/loader:1134:3) at require (node:internal/modules/cjs/helpers:110:18) at setupNodeEvents (file:///C:/Users/XXX/testing/cypress.config.js:49:90)
Now, on to the resolution:
- Import the
cypress-mochawesome-reporter/plugin
module as an ES6 import:import plugin from 'cypress-mochawesome-reporter/plugin';
- Update the static
require('cypress-mochawesome-reporter/plugin')( on )
line toplugin( on )
Cypress should load the plugin correctly.
Hopefully this helps!
This fixes the issue reported :) Thank you sir.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
Environment
What happened?
Current behavior
Hello team,
I am following the instructions here, to setup Cypress HTML report using package cypress-mochawesome-reporter however I am getting the following error:
Expected behavior
When I run
yarn cypress run --browser chrome
, in the terminal, I should see cypress-mochawesome-reporter produce sample output below:Config file
Relevant log output