cypress-cucumber-preprocessor: TypeScript tests fail with `ParseError: 'import' and 'export' may appear only with 'sourceType: module'`
Attempting to set up cypress-cucumber-preprocessor
with add-typescript-to-cypress
, I receive the following error when running a .feature
test in Cypress whose step definitions are in a steps.ts
file containing an import
statement:
Error running plugin
The following error was thrown by a plugin. We've stopped running your tests because a plugin crashed.
...
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Running a separate spec.ts
file containing an import
using only @bahmutov/add-typescript-to-cypress
in cypress/plugins/index.js
works fine, but as soon as I add on('file:preprocessor', cucumber());
TypeScript tests containing import
fail with the same error.
I see other open issues related to that same error but for ES6, not TypeScript (targeting ES5), so I am opening this case.
Versions:
- cypress@3.0.1
- cypress-cucumber-preprocessor@1.0.0
- @bahmutov/add-typescript-to-cypress@2.0.0
- node@8.11.2
- MacOS X 10.13.5
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15
Thanks, @sloosch & @lgandecki!
I confirm that the diffs above allow use of some TypeScript with
cypress-cucumber-preprocessor
. However, I notice that one can’t use TypeScript standardimport
orexport
statements. Any remedy for either of those shortcomings?can you try using require instead of import?
@sloosch yeah, that sounds like a workable hack 😃 I might try it. Thanks for the input.
Btw, TypeScript works with 1.2.0! I’ve added instructions to the readme in 1.2.1
@KeithGillette These are the only changes You’d have to make in your repro to get your example to work:
Hi @KeithGillette, we ran into the same problem during evaluation of cypress + gherkin due to this and #52, #51 and #44 (which can be overcome by using a beforeStep-Hook) i have created https://www.npmjs.com/package/gherkin-to-mocha which is a webpack loader which transforms gherkin files into a mocha test suite. By using https://github.com/cypress-io/cypress-webpack-preprocessor you can have feature files and typescript steps/hooks. In the end we have decided against cypress because there is no support for Firefox and IE… anyway you may find the loader useful for your project.
Thanks, I will take a look Friday/Saturday 😃