TypeScript tests fail with `ParseError: 'import' and 'export' may appear only with 'sourceType: module'`
See original GitHub issueAttempting 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:15
Top Results From Across the Web
Cypress ParseError: 'import' and 'export' may appear only with ...
This error is caused by the presence of modern keywords like "import" and "export" when Cypress runs in the browser.
Read more >'import' and 'export' may appear only with 'sourceType: module ...
'import' and 'export' may appear only with 'sourceType: module' at EventEmitter.handler with implementation Cucumber + TypeScript and cypress-firebase.
Read more >Cypress ParseError: 'import' and 'export' may appear only with ...
This error is caused by the presence of modern keywords like "import" and "export" when Cypress runs in the browser. Unlike Selenium or...
Read more >'import' and 'export' may appear only with 'sourceType: module ...
Parsing error on .vue files during typescript analysis with javascript sensor - 'import' and 'export' may appear only with 'sourceType: ...
Read more >cypress parseerror unexpected character
parseerror : 'import' and 'export' may appear only with 'sourcetype: ... A TypeScript module can say export default myFunction to export just one...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?