Search code examples
javascripttypescriptcypresscypress-configuration

Cypress - error occurs when I installed 'del' module, cant open cypress


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

then I configured cypress config but this line:

const del = require('del')

makes that cypress is not working (I cant even select any browser): enter image description here enter image description here

When I commented out this line (const del = require('del')), cypress worked normally.

How can I fix it?

  • Cypress version: 12.5
  • del version: 7.0.0

Solution

  • The latest version of del v7.0.0 isn't compatible with the example code Cypress gives.

    You could downgrade to v6.1.1 and the sample code will run.

    npm install del@6.1.1
    

    I would remove ver 7.0.0 first to be sure you get the older version installed.


    You can use ver 7.0.0 and alter the code to use dynamic import.

    The newest version also changes the function names to deleteAsync and deleteSync, so the usage is slightly different.

    Here's the changes to the Cypress sample code:

    const { defineConfig } = require('cypress')
    
    module.exports = defineConfig({
      e2e: {
        setupNodeEvents(on, config) {
          on('after:spec', (spec, results) => {
            if (results && results.stats.failures === 0 && results.video) {
              return import('del').then(del => {
                return del.deleteSync(results.video)
              })
            }
          })
        },
      },
    })