Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: only restart esm on Node 16+ (#12955)

Pavel Feldman3f1cb7b8e60a
diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.ts
index 27b6641539..e6764d0963 100644
--- a/packages/playwright-test/src/cli.ts
+++ b/packages/playwright-test/src/cli.ts
@@ -243,6 +243,10 @@ async function launchDockerContainer(): Promise<() => Promise<void>> {
}
function restartWithExperimentalTsEsm(configFile: string | null): boolean {
+ const nodeVersion = +process.versions.node.split('.')[0];
+ // New experimental loader is only supported on Node 16+.
+ if (nodeVersion < 16)
+ return false;
if (!configFile)
return false;
if (process.env.PW_DISABLE_TS_ESM)
diff --git a/packages/playwright-test/src/loader.ts b/packages/playwright-test/src/loader.ts
index 755ec3ba3c..b2564a188e 100644
--- a/packages/playwright-test/src/loader.ts
+++ b/packages/playwright-test/src/loader.ts
@@ -252,8 +252,13 @@ export class Loader {
if (didYouMean?.endsWith('.ts'))
throw errorWithFile(file, 'Cannot import a typescript file from an esmodule.');
}
- if (error.code === 'ERR_UNKNOWN_FILE_EXTENSION' && error.message.includes('.ts'))
- throw errorWithFile(file, 'Cannot import a typescript file from an esmodule.');
+ if (error.code === 'ERR_UNKNOWN_FILE_EXTENSION' && error.message.includes('.ts')) {
+ throw errorWithFile(file, `Cannot import a typescript file from an esmodule.\n${'='.repeat(80)}\nMake sure that:
+ - you are using Node.js 16+,
+ - your package.json contains "type": "module",
+ - you are using TypeScript for playwright.config.ts.
+${'='.repeat(80)}\n`);
+ }
if (error instanceof SyntaxError && error.message.includes('Cannot use import statement outside a module'))
throw errorWithFile(file, 'JavaScript files must end with .mjs to use import.');