javierbrea / cypress-localstorage-commands

Extends Cypress' cy commands with localStorage methods. Allows preserving localStorage between tests and spec files. Allows disabling localStorage.
MIT License
178 stars 9 forks source link

Got ReferenceError: require is not defined #565

Open daisypreeti opened 4 months ago

daisypreeti commented 4 months ago

Describe the bug Got ReferenceError: require is not defined

To Reproduce After installing run the test

Expected behavior instead of require what else we can use to configure in the cypress.config.ts

javierbrea commented 4 months ago

Hi @daisypreeti ,

I suppose that you are referring to install the plugin node events in the Cypress configuration. And it seems that you are trying to install it in a TypeScript config by copying directly the installation example in the docs, am I right? (please, next time provide more context, details, code examples, etc.)

Anyway, note that the plugin is a CommonJS module, and, so, you should use the appropriated syntax when importing it in TypeScript

For example:

import plugin = require("cypress-localstorage-commands/plugin");

export default {
  e2e: {
    setupNodeEvents(on, config) {
      plugin(on, config);
    },
  },
}

I hope this helps. Please let me know.