Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Improve error message when attempting to compile TypeScript file and typescript support is not enabled #47

Closed
chrisbreiding opened this issue May 8, 2020 · 3 comments · Fixed by #52
Labels

Comments

@chrisbreiding
Copy link
Collaborator

Current behavior:

If you don't pass the typescript option, but have TypeScript files, it results in a syntax error.

SyntaxError: Unexpected token (3:10) while parsing /path/to/project/cypress/integration/typescript_spec.ts while parsing file: /path/to/project/cypress/integration/typescript_spec.ts

See also this issue comment.

This is particularly problematic in the default Cypress behavior, since we try to pass the typescript option automatically by auto-detecting it. If we fail to find it and don't pass the option, but the user has TypeScript files, it fails at runtime with the above cryptic syntax error.

Desired behavior:

We should error early if attempting to compile a .ts or .tsx file and the typescript option is not set. In the error message, we can make it clear what went wrong and provide remediation options.

How to reproduce:

Create a TypeScript spec (cypress/integration/typescript_spec.js) and add some TypeScript-specific syntax:

interface Foo {
  baz: string
}

Run Cypress and it will fail with a syntax error.

@mike-hogan
Copy link

@chrisbreiding this suggests that if I pass the typescript option, things will work. Where and how do I pass this option?

Thanks

@chrisbreiding
Copy link
Collaborator Author

You can use it by using this package directly. Check out the installation and usage directions the the typescript directions.

Cypress uses this package under the hood and tries to auto-detect the path to your typescript installation, but it seems that may not work in all cases, so providing the path manually might make it work.

@chrisbreiding
Copy link
Collaborator Author

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants