cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

"Delete the recorded video if the spec passed" code snippet causes error due to ESM

Open ZachJW34 opened this issue 3 years ago • 0 comments

Description

The code snippet says to download del and require('del') but the latest version only supports ESM

URL of Issue(s)

https://docs.cypress.io/api/plugins/after-spec-api#Delete-the-recorded-video-if-the-spec-passed

Steps to replicate

  1. Checkout kitchen sink
  2. cd into directory and run npm i -D del
  3. Copy code snippet for https://docs.cypress.io/api/plugins/after-spec-api#Examples into cypress.config.js
  4. Run cypress with npx cypress run, see error
Your configFile is invalid: /Users/zachjw/work/firewatch-triage/cypress-test-tiny/cypress.config.js

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

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/zachjw/work/firewatch-triage/cypress-test-tiny/node_modules/del/index.js from /Users/zachjw/work/firewatch-triage/cypress-test-tiny/cypress.config.js not supported.
Instead change the require of index.js in /Users/zachjw/work/firewatch-triage/cypress-test-tiny/cypress.config.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/zachjw/work/firewatch-triage/cypress-test-tiny/cypress.config.js:1:13)
    at async Promise.all (index 0)
    at async loadFile (/Users/zachjw/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:106:14)
    at async EventEmitter.<anonymous> (/Users/zachjw/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:116:32)

Browser

na

Device

  • [ ] PC
  • [ ] Mac
  • [ ] iPhone
  • [ ] iPad
  • [ ] Android Phone
  • [ ] Android Tablet

Additional Information

The code snippet should be updated to recommend installing [email protected] which is the last version published that targets commonjs or use a dynamic import e.g. await import('del') if using the latest version.

ZachJW34 avatar Sep 16 '22 20:09 ZachJW34