chore: remove esm error interception, it only confuses users (#14829)

This commit is contained in:
Pavel Feldman 2022-06-13 11:32:42 -08:00 committed by GitHub
parent dcdd3c3cdb
commit 88664c39c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 16 deletions

View File

@ -275,21 +275,6 @@ export class Loader {
if (isModule)
return await esmImport();
return require(file);
} catch (error) {
if (error.code === 'ERR_MODULE_NOT_FOUND' && error.message.includes('Did you mean to import')) {
const didYouMean = /Did you mean to import (.*)\?/.exec(error.message)?.[1];
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.\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`);
}
throw error;
} finally {
revertBabelRequire();
}

View File

@ -238,7 +238,7 @@ test('should fail to load ts from esm when package.json has type module', async
});
expect(result.exitCode).toBe(1);
expect(result.output).toContain('Cannot import a typescript file from an esmodule');
expect(result.output).toContain('Unknown file extension ".ts"');
});
test('should filter stack trace for simple expect', async ({ runInlineTest }) => {