question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript tests fail with `ParseError: 'import' and 'export' may appear only with 'sourceType: module'`

See original GitHub issue

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:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15

github_iconTop GitHub Comments

9reactions
KeithGillettecommented, Oct 26, 2018

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 standard import or export statements. Any remedy for either of those shortcomings?

6reactions
lgandeckicommented, Jun 22, 2018

can you try using require instead of import?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found