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

Can't import TypeScript module into the pluginsFile

Open gon opened this issue 5 years ago • 0 comments

Hi! We're bringing in Cypress into our React app written in TypeScript. We're hitting a roadblock with creating a Cypress Task that would need to use a class from our app code to call our DB (Firebase) and clean up data from an afterEach hook.

Using this example setup repo, we're finding the same error shows up once we try to require a class from the app code from the pluginsFile (plugins/index.js).

The following error appears after making these 3 changes:

  • create src/exemplaryClass.ts with an empty class like so: export default class ExemplaryClass {}
  • add const exemplaryClass = require("../../src/exemplaryClass") at the top of the pluginsFile
  • set the tsconfig.json to "target": "es6", "module": "esnext"

(...)/cypress-ts/src/exemplaryClass.ts:1 export default class ExemplaryClass { ^^^^^^

SyntaxError: Unexpected token 'export'

It looks like the pluginsFile needs to be in ES5 (thus using require) and the file isn't then allowed to use ES6. Is that correct?

Do you have an idea on how to make this work?

gon avatar May 01 '20 06:05 gon