elgentos / magento2-cypress-testing-suite

A community-driven Cypress testing suite for Magento 2
MIT License
172 stars 37 forks source link

Dependency of node "module" can not be used with "require()" #99

Open Vinai opened 2 years ago

Vinai commented 2 years ago

Describe the bug

The PR https://github.com/elgentos/magento2-cypress-testing-suite/pull/98 breaks the config with

Your configFile is invalid: ...magento2-cypress-testing-suite/cypress.config.js

It threw an error when required, check the stack trace below:

Error [ERR_REQUIRE_ESM]: require() of ES Module ...magento2-cypress-testing-suite/node_modules/del/index.js from ...magento2-cypress-testing-suite/cypress.config.js not supported.
Instead change the require of index.js in /Volumes/CaseSensitive/Workspace/php-sites/mos-hyva-245/magento2-cypress-testing-suite/cypress.config.js to a dynamic import() which is available in all CommonJS modules.

The problem is that del@7.0.0 is a node module, not a library (see "type": "module", in the del package.json). This means it needs to be used with import. The most simple fix is to use const del = import('del'); However, I suggest removing the dependency, since deleting folders and files is a trivial problem - node offers all that is needed out of the box (since fs is already imported):

return fs.rmdirSync(results.video, {recursive: true})

To Reproduce

git checkout main
git pull
npm ci
npx cypress run

Expected behavior Cypress runs tests

Screenshots

Bildschirmfoto 2022-10-13 um 13 26 57
Vinai commented 2 years ago

The same PR also introduced additional issues by using _ which is not defined.