Skip to content

[REGRESSION]: import with TypeScript path not resolved correctly since v1.35.0 #26650

@OliverJAsh

Description

@OliverJAsh

Context:

  • GOOD Playwright Version: 1.34.3
  • BAD Playwright Version: 1.35.0 and above
  • Operating System: macOS

Code Snippet

Full reduced test case: https://github.com/OliverJAsh/playwright-pkg-require-with-path

Contents inlined below:

tsconfig.json:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "app/*": ["app/*"]
        }
    }
}

app/my-pkg/main.ts:

export const foo = 1;

app/my-pkg/package.json:

{
  "main": "main.ts"
}

tests/example.spec.ts:

// ❌ Using path, it doesn't work.
import * as x from 'app/my-pkg';
// ✅ Not using path, it works.
// import * as x from '../app/my-pkg';

console.log(x);

Describe the bug

Starting with Playwright 1.35.0, Playwright returns an error: Error: Cannot find module 'app/my-pkg'.

Note that if we change the import to avoid using the TS path (app/*), it works:

import * as x from '../app/my-pkg';

console.log(x);
$ yarn
$ yarn playwright test
yarn run v1.22.19
Error: Cannot find module 'app/my-pkg'
Require stack:
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/tests/example.spec.ts
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/transform/transform.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/common/config.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/reporters/json.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/reporters/raw.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/reporters/html.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/runner/reporters.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/runner/runner.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/lib/cli.js
- /Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/node_modules/@playwright/test/cli.js

   at example.spec.ts:2

  1 | // ❌ Using path, it doesn't work.
> 2 | import * as x from 'app/my-pkg';
    | ^
  3 | // ✅ Not using path, it works.
  4 | // import * as x from '../app/my-pkg';
  5 |

    at Object.<anonymous> (/Users/oliver/Code/Reduced test cases/playwright-pkg-require-with-path/tests/example.spec.ts:2:1)

Error: No tests found







To open last HTML report run:

  npx playwright show-report

error Command failed with exit code 1.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions