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] Playwright Imports & Path Aliases

See original GitHub issue

Hi all! šŸ‘‹ I’m currently working in a monorepo with a few different apps, and I’d like to isolate some of the custom code that I’ve written for my Playwright setup to a shared library, that can be used for those respective apps.

In the root of our project, I have the following in a tsconfig.base.json file:

"paths": {
	"@app/end2end/*": ["libs/end2end/src/lib/*"],
	"@app/end2end": ["libs/end2end/src/index.ts"],
}

All of the tsconfig.jsons throughout each individual project and library extend from this base configuration.

This is pretty handy, because it means that when I import the extended ā€˜test’ object with all my custom fixtures inside of apps/app-e2e/tests/test.spec.ts, I can write this:

import { test } from "@app/end2end";

instead of this:

import { test } from "../../../libs/end2end/src";

which I think we can all agree is a bit of an eyesore.

But there’s one problem: the code that I wrote above doesn’t actually work šŸ˜… When I try to execute test.spec.ts, either from the VS Code test runner or from the terminal with an npm script, nothing actually happens. A node process will be initiated, but then immediately close. There aren’t even any errors to indicate what might be going wrong.

Similarly, when I tried to write the following inside of my playwright.config.ts:

globalSetup: require.resolve("@app/end2end/env/global-setup"),

I get a name resolution error. Playwright doesn’t interact with the Typescript compiler to find the appropriate file, for a given path alias.

In my search for solutions, I of course came across #7121, where a number of other users reported their problems with interoperability between customized tsconfig options and Playwright. But developer comments at the end of that thread seem to indicate that these features had been added to the Playwright test runner as of February, and that the issue was largely resolved.

So my question is: what changes do I need to make to correctly utilize path aliases in my test and config files?

I’m not filing this as a bug, because my preliminary research seems to indicate that this was a bug, but has now been resolved. It’s a lack of knowledge on my part, not a missing feature or defect in the software itself.

Thanks for reading, any advice would be very appreciated 😁

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mxschmittcommented, Aug 8, 2022

We as of today don’t process extends inside tsconfig afaik

A sparse tsconfig file with extends is how SvelteKit apps are scaffolded today by default. Are you sure?

You are right, I updated my comment above.

1reaction
vhscomcommented, Aug 8, 2022

We as of today don’t process extends inside tsconfig afaik

A sparse tsconfig file with extends is how SvelteKit apps are scaffolded today by default. Are you sure?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript + Playwright Error: Cannot find module
How to solve this problem? there are codes below. test.spec.ts import { chromium, ChromiumBrowser, Page } fromĀ ...
Read more >
Path aliases with TypeScript in Node.js - Level Up Coding
In this article, I will walk you through setting up path aliases in your TypeScript ... In Node.js (or TS/JS in general) you...
Read more >
Typescript – How to solve the problem with unresolved path ...
Path aliases are defined as an array of key-value objects with the ā€œpathsā€: key. Paths setting, usually require to set also the ā€œbaseUrlā€...
Read more >
Getting rid of relative paths in imports using webpack alias
Traditionally we import a component by mentioning the directory using combination of dots and slashes. The problem with this approach is that this...
Read more >
API - ESBuild
Note that when an import path is substituted using an alias, ... In the browser, you can load a module using <script src="file.js"...
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