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.

[Question] Typescript Monorepo Tsx Issue

See original GitHub issue

I am getting the following error:

SyntaxError: Unexpected token '<'

Because, deep in my test’s dependency tree, I import a tsx file. Any workaround for this would be awesome, because this error is currently blocking adoption.

More details on my project setup below:

We are looking to adopt playwright for e2e testing one of our sites. The site is located in a typescript monorepo. Some packages in the typescript monorepo are only used internally, and so are not compiled. One of these packages is our “core” package in which we locate all of our core business logic. This package handles database interactions, sending email, accepting payments, etc. All use case logic is in the “core” package. Our strategy for authoring html emails is to use react, giving us reusable components for all our emails. So, deep in the “core” package, we import jsx/tsx files.

Since the core package also handles database interactions, it exposes a set of functions used to seed data, like SeedFoo, and SeedBar. These seed functions are called before some end to end tests to provide the appropriate data state for the site.

So, our tests import core and core contains tsx files, causing the error above.

Is there any workaround to allow playwright tests to import tsx files (even indirectly)? In not, is this on the roadmap at some point?

Note: We are not using component testing at this time. We are not trying to import these components in the context of component testing. And we cannot have these email related react components subject to same limitations as component testing (ie no react fragments).

Any help people can offer would be greatly appreciated.

Thank you! 😃

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rubber-duck-softwarecommented, Oct 11, 2022

I think we have a different understanding of the typescript compiler and its role in the larger ecosystem.

From the typescript docs here

TypeScript supports embedding, type checking, and compiling JSX directly to JavaScript.

I believe the JSX transform is a special case in the JS transpilation ecosystem since typescript supports it natively (without webpack / babel, rollup / esbuild, etc). Further, since JSX is just transformed into Javascript, it can execute correctly in Node.js, not just in the browser.

As for other tools which support Node.js TSX, this isn’t something that I think of tools explicitly supporting. This is done simply with a typescript compilation. On our backend, we use tsx files in Node.js, run with ts-node using swc as our compiler. Currently, we have use cypress for e2e testing and these tsx files are imported into cypress tasks (run Node.js in cypress).

My interpretation of this is that playwright’s support for typescript is incomplete since typescript will transform JSX but playwright cannot. I have very little experience with playwright and certainly don’t understand how it works internally. Any help you could provide (or any correction you can offer) would be welcome.

Thank you!

0reactions
rubber-duck-softwarecommented, Oct 12, 2022

Wow! Thanks much for looking at this, that’s really great! I’m super excited to get to use playwright on this project going forward.

Thanks for your attention on this issue. Looking forward to 1.28!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSX files in adjacent yarn workspace packages result ... - GitHub
Describe the bug react-scripts cannot load tsx files that are in adjacent yarn workspace packages. Module parse failed: Unexpected token.
Read more >
Module's not resolving in typescript monorepo with Next.js ...
This works just fine, however, the problem happens when a component in app-2 imports other components like import Component from "components/ ...
Read more >
How to Create a React Typescript Monorepo with Git ...
We would like a way to include that project inside our monorepo, but not create a separate copy.
Read more >
Bun is a fast all-in-one JavaScript runtime - Things Typescript
Bun is a self-contained JavaScript runtime, i.e., unlike NodeJS, which doesn't handle building/bundling your project, just the runtime part, ...
Read more >
Fix go to definition and hot reload in a react typescript monorepo
Hot reload boils down to a single problem: by default, react is configured to only import/watch for file changes inside the /src directory....
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