chore: only restart esm on Node 16+ (#12955)
This commit is contained in:
Родитель
81d412216a
Коммит
3f1cb7b8e6
|
@ -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)
|
||||
|
|
|
@ -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.');
|
||||
|
|
Загрузка…
Ссылка в новой задаче