Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] TypeScript not working with "type": "module" // Unknown file extension ".ts" #15862

Closed
sonntag-philipp opened this issue Jul 21, 2022 · 3 comments · Fixed by #15866
Closed

Comments

@sonntag-philipp
Copy link

Context

  • Playwright Version: 1.23.4
  • Operating System: Windows
  • Node.js version: 14.20.0 and > 16
  • Browser: All, Chromium, Firefox, WebKit
  • Extra: I used nvm for Windows to switch the NodeJS versions.

Console log

C:\Users\psn\Desktop\playwright-module-test> node --version
v16.16.0
C:\Users\psn\Desktop\playwright-module-test> npx playwright test
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
(node:9712) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time(Use `node --trace-warnings ...` to show where the warning was created)

Running 3 tests using 3 workers

  3 passed (9s)

To open last HTML report run:

  npx playwright show-report

C:\Users\psn\Desktop\playwright-module-test> node --version
v14.20.0
C:\Users\psn\Desktop\playwright-module-test> npx playwright test
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\psn\Desktop\playwright-module-test\playwright.config.ts
    at new NodeError (internal/errors.js:322:7)
    at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)
    at Loader.getFormat (internal/modules/esm/loader.js:105:42)
    at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)
    at Loader.import (internal/modules/esm/loader.js:177:17)
    at Loader._requireOrImport (C:\Users\psn\Desktop\playwright-module-test\node_modules\@playwright\test\lib\loader.js:275:28)
    at Loader._requireOrImportDefaultObject (C:\Users\psn\Desktop\playwright-module-test\node_modules\@playwright\test\lib\loader.js:290:18)
    at Loader.loadConfigFile (C:\Users\psn\Desktop\playwright-module-test\node_modules\@playwright\test\lib\loader.js:79:20)
    at Runner.loadConfigFromResolvedFile (C:\Users\psn\Desktop\playwright-module-test\node_modules\@playwright\test\lib\runner.js:96:12)
    at runTests (C:\Users\psn\Desktop\playwright-module-test\node_modules\@playwright\test\lib\cli.js:153:27)
    at Ai.<anonymous> (C:\Users\psn\Desktop\playwright-module-test\node_modules\@playwright\test\lib\cli.js:70:7) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
C:\Users\psn\Desktop\playwright-module-test>

package.json

{
  "name": "playwright-module-test",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {},
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@playwright/test": "^1.23.4"
  }
}

Describe the bug
The TypeScript support in combination with "type": "module" seems to be only working in NodeJS >= v16.
Combining TypeScript with "type": "commonjs" also worked in NodeJS v14.

I don't think that this is a big problem as the current LTS version is 16. The documentation in terms of the TypeScript support should be updated I guess so others don't waste time looking for a solution. Currently, the trouble shooting area in the documentation only sets NodeJS v14 as minimum requirement under which this case does not work anymore.

@dgozman
Copy link
Contributor

dgozman commented Jul 22, 2022

@sonntag-philipp Indeed, "type": "module" mode only works with Node >= 16. Let me update the docs.

@gunters63
Copy link

gunters63 commented Sep 6, 2022

I have:

$ node -v
v16.17.0

and

 "@playwright/test": "^1.25.1

here and still have the same problem:

$ npx playwright test

Running 0 tests using 0 workers

TypeError: Unknown file extension ".ts" for D:\proj\AtlasCopco\EnsoUi\apps\ui-docs-v1\tests\snapshot.spec.ts

    at async Promise.all (index 0)
=================
 no tests found.
=================


  1 error was not a part of any test, see above for details

Only when I remove "type": "module" from package.json it works.

@fedetibaldo
Copy link

This hasn't been resolved. It's still an issue to the present date. See https://github.com/fedetibaldo/playwright-typescript-module-bug for a minimal reproduction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants