Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
6 tasks
ZachJW34 opened this issue Sep 16, 2022 · 2 comments
Closed
6 tasks

Comments

@ZachJW34
Copy link
Contributor

ZachJW34 commented Sep 16, 2022

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.

@Ioanna2001
Copy link

Hello, is this up for grabs? I would like to try and tackle it

@MikeMcC399
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants