Can't import TypeScript module into the pluginsFile
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.tswith an empty class like so:export default class ExemplaryClass {} - add
const exemplaryClass = require("../../src/exemplaryClass")at the top of the pluginsFile - set the
tsconfig.jsonto"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?