[Feature]: Resolve Node.js subpath imports (package.json "imports") to TypeScript sources

Abierto
#43,966 7 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
57/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, playwright, typescript
Área
backend, testing

Línea de trabajo

Start by comparing Playwright’s TypeScript path alias resolution with Node.js package.json "imports" resolution; the issue gives a minimal project layout and failing import in src/tests/get-env.test.ts. Run npx playwright test with the provided repro and confirm the test file loads when the alias is configured through "imports". Done when that import resolves to the TypeScript source and the test passes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

needs-triage
🚀 Feature Request

Playwright resolves TypeScript path aliases from tsconfig.json (paths), but not the Node.js subpath imports mechanism (the package.json "imports" field) when the targets are TypeScript sources.

Re-filing with a concrete use case after the closure of #40062 (part of the P3-collecting-feedback cleanup described in #43813). Reproduced and verified against the latest version, @playwright/[email protected].

Two minimal, otherwise-identical projects demonstrate the inconsistency: the only difference between them is the resolution mechanism.

Project layout (both variants):

├── package.json
├── playwright.config.ts
├── tsconfig.json
└── src/
    ├── utils/env.ts
    └── tests/get-env.test.ts

src/utils/env.ts:

export function getEnv(name: string): string {
  const value = process.env[name];
  if (value === undefined) {
    throw new Error(`Missing environment variable: ${name}`);
  }
  return value;
}

src/tests/get-env.test.ts:

import { test, expect } from "@playwright/test";
import { getEnv } from "#/utils/env";

test("getEnv resolves a variable via the subpath import", () => {
  process.env.PW_REPRO_VAR = "playwright";
  expect(getEnv("PW_REPRO_VAR")).toBe("playwright");
});

playwright.config.ts:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  testDir: './src/tests',
});

Variant A — works (tsconfig.json path alias):

{
  "compilerOptions": {
    "paths": { "#/*": ["./src/*"] }
  }
}

Variant B — fails (package.json subpath imports, same tsconfig.json minus paths):

{
  "type": "module",
  "imports": {
    "#/*": ["./src/*", "./src/*.ts", "./src/*/index.ts"]
  }
}

Run npx playwright test in each variant. Variant B fails when loading the test file:

Error: Cannot find module 'C:\path\to\repro\src\utils\env' imported from C:\path\to\repro\src\tests\get-env.test.ts
    at eval (<anonymous>:1:1)
Error: No tests found

Both repro projects are attached as a zip archive.

Environment: @playwright/[email protected] (latest), Node.js v24.22.1, Windows.

pw-repro (node).zip

pw-repro (ts).zip

Example

A project aliases its imports via the package.json "imports" field:

{
  "type": "module",
  "imports": {
    "#/*": ["./src/*", "./src/*.ts", "./src/*/index.ts"]
  }
}

The same specifier #/utils/env resolves fine with tsc and at runtime under Node, but npx playwright test fails with Cannot find module '...\src\utils\env' before any test runs.

Motivation

Today, the same import specifier resolves or fails depending on whether it goes through tsconfig.json paths or package.json imports. Supporting imports to TypeScript sources would make Playwright's resolver consistent with the Node.js and TypeScript ecosystems.

Lenguaje dominante
TypeScript
Estrellas
99.1k
Forks
6.8k
Merge medio
17 h 6 min
PR fusionados (30 d)
306

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/playwright

Todos los issues de microsoft/playwright

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.