{"id":16293581,"url":"https://github.com/badsyntax/playwright-test-repo","last_synced_at":"2026-04-30T09:37:33.937Z","repository":{"id":136895243,"uuid":"416998579","full_name":"badsyntax/playwright-test-repo","owner":"badsyntax","description":"An example repo showing issues when importing an ES Module in your @playwright/test test file, and a workaround.","archived":false,"fork":false,"pushed_at":"2021-10-14T07:05:00.000Z","size":43,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T11:13:34.660Z","etag":null,"topics":["playwright","playwright-test-runner"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/badsyntax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-14T05:22:12.000Z","updated_at":"2021-11-03T13:15:58.000Z","dependencies_parsed_at":"2023-04-14T01:30:53.688Z","dependency_job_id":null,"html_url":"https://github.com/badsyntax/playwright-test-repo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/badsyntax/playwright-test-repo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fplaywright-test-repo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fplaywright-test-repo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fplaywright-test-repo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fplaywright-test-repo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badsyntax","download_url":"https://codeload.github.com/badsyntax/playwright-test-repo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fplaywright-test-repo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32460781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"online","status_checked_at":"2026-04-30T02:00:05.929Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["playwright","playwright-test-runner"],"created_at":"2024-10-10T20:11:47.836Z","updated_at":"2026-04-30T09:37:33.922Z","avatar_url":"https://github.com/badsyntax.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `@playwright/test` issue with ES modules\n\nAn example repo showing issues when importing an ES Module in your `@playwright/test` test file, and a workaround.\n\n## Getting Started\n\n```console\nnvm use\nnpm i\nnpx playwright install\nnpm test\n```\n\nYou should see:\n\n```console\n❯ npm test\n\n\u003e playwright-test-repo@1.0.0 test\n\u003e playwright test\n\nUsing config at /Users/richardwillis/Projects/chevin/playwright-test-repo/playwright.config.ts\nTypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension \".ts\" for /Users/richardwillis/Projects/chevin/playwright-test-repo/src/tests/modules/Example.test.ts\n    at new NodeError (node:internal/errors:371:5)\n    at Loader.defaultGetFormat [as _getFormat] (node:internal/modules/esm/get_format:71:15)\n    at Loader.getFormat (node:internal/modules/esm/loader:105:42)\n    at Loader.getModuleJob (node:internal/modules/esm/loader:243:31)\n    at Loader.import (node:internal/modules/esm/loader:177:17)\n    at importModuleDynamicallyWrapper (node:internal/vm/module:437:15)\n    at Loader._requireOrImport (/Users/richardwillis/Projects/chevin/playwright-test-repo/node_modules/@playwright/test/lib/test/loader.js:214:52)\n    at Loader.loadTestFile (/Users/richardwillis/Projects/chevin/playwright-test-repo/node_modules/@playwright/test/lib/test/loader.js:130:7)\n    at Runner._run (/Users/richardwillis/Projects/chevin/playwright-test-repo/node_modules/@playwright/test/lib/test/runner.js:219:40) {\n  code: 'ERR_UNKNOWN_FILE_EXTENSION'\n}\n```\n\n... because we're doing `import { importFromEsModule } from '../../../ESModule';` in one of our test files.\n\n## Workaround\n\n`@playwright/test` doesn't support automatic typescript transpilation for esm modules so we need to manually compile ourselves.\n\nOur [compilation target module](https://github.com/badsyntax/playwright-test-repo/blob/85ad27942cf9ba55dff4724d0d4b115747b5fcea/tests/tsconfig.json#L3) type MUST be `commonjs` UNLESS we change all our import paths (see \u003chttps://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#esm-nodejs\u003e).\n\nOur [package type](https://github.com/badsyntax/playwright-test-repo/blob/85ad27942cf9ba55dff4724d0d4b115747b5fcea/package.json#L9) MUST be `commonjs` UNLESS we are compiling to ES modules.\n\nRun `npm run test:fix` to see the workaround:\n\n```console\n❯ npm run test:fix\n\n\u003e playwright-test-repo@1.0.0 pretest:fix\n\u003e tsc --incremental -p tests/tsconfig.json\n\n\n\u003e playwright-test-repo@1.0.0 test:fix\n\u003e playwright test -c tests-out\n\n\nRunning 1 test using 1 worker\n\n  ✓  ../tests/Example.test.ts:7:5 › basic test (1s)\n\n\n  1 passed (2s)\n```\n\nThe above script has a pre-script hook: `\"pretest:fix\": \"tsc --incremental -p tests/tsconfig.json\",` which compiles the test files into commonjs modules which `@playwright/test` runs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadsyntax%2Fplaywright-test-repo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadsyntax%2Fplaywright-test-repo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadsyntax%2Fplaywright-test-repo/lists"}