From e28b213b69c1106d57b3aa08da1f9a891b3fc2ae Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Thu, 2 Sep 2021 04:40:07 +0000 Subject: [PATCH 1/5] Make the syntax error message more helpful I got this error when trying to use jest with typescript. Turns out the info I needed was on https://jestjs.io/docs/getting-started#using-typescript : I needed to install babel and create babel.config.js --- packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts index 272381bbf1a4..35af795b6c89 100644 --- a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts +++ b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts @@ -45,6 +45,7 @@ Here's what you can do: ${DOT}If you are trying to use ECMAScript Modules, see ${chalk.underline( 'https://jestjs.io/docs/ecmascript-modules', )} for how to enable it. +${DOT}If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript ${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${chalk.bold( '"transformIgnorePatterns"', )} in your config. From e06e34bcb159c06450381d9df8937d6f172e8a9d Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 19 Sep 2021 11:18:27 +0000 Subject: [PATCH 2/5] Apply review suggestions --- packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts index 35af795b6c89..77764b35f115 100644 --- a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts +++ b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts @@ -45,7 +45,7 @@ Here's what you can do: ${DOT}If you are trying to use ECMAScript Modules, see ${chalk.underline( 'https://jestjs.io/docs/ecmascript-modules', )} for how to enable it. -${DOT}If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript +${DOT}If you are trying to use TypeScript, see ${chalk.underline('https://jestjs.io/docs/getting-started#using-typescript')} ${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${chalk.bold( '"transformIgnorePatterns"', )} in your config. From 106cad5e2327fbfa1743bb320f95638d6290dd51 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 19 Sep 2021 11:24:57 +0000 Subject: [PATCH 3/5] Add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0af283259c24..6d95c20977ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- `[jest-transform]` Improve the unexpected token error message. ([#11807](https://github.com/facebook/jest/pull/11807)) + ### Fixes ### Chore & Maintenance From 4a2ec9bb73c4a5a9977c655d174519026840f196 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 19 Sep 2021 11:53:09 +0000 Subject: [PATCH 4/5] lint --- packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts index 77764b35f115..1f319db5b4ef 100644 --- a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts +++ b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts @@ -45,7 +45,9 @@ Here's what you can do: ${DOT}If you are trying to use ECMAScript Modules, see ${chalk.underline( 'https://jestjs.io/docs/ecmascript-modules', )} for how to enable it. -${DOT}If you are trying to use TypeScript, see ${chalk.underline('https://jestjs.io/docs/getting-started#using-typescript')} +${DOT}If you are trying to use TypeScript, see ${chalk.underline( + 'https://jestjs.io/docs/getting-started#using-typescript' + )} ${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${chalk.bold( '"transformIgnorePatterns"', )} in your config. From 989dc36f6a3fd0dfef9df85cd29eadeb467ce5c9 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 19 Sep 2021 12:09:08 +0000 Subject: [PATCH 5/5] lint --- packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts index 1f319db5b4ef..469e53c71659 100644 --- a/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts +++ b/packages/jest-transform/src/enhanceUnexpectedTokenMessage.ts @@ -46,7 +46,7 @@ ${DOT}If you are trying to use ECMAScript Modules, see ${chalk.underline( 'https://jestjs.io/docs/ecmascript-modules', )} for how to enable it. ${DOT}If you are trying to use TypeScript, see ${chalk.underline( - 'https://jestjs.io/docs/getting-started#using-typescript' + 'https://jestjs.io/docs/getting-started#using-typescript', )} ${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${chalk.bold( '"transformIgnorePatterns"',