From c1b494c22edf40d0497d5ee077a40af032dc1bf1 Mon Sep 17 00:00:00 2001 From: Juan Carlos Valerio Date: Wed, 10 Jun 2020 17:39:28 -0600 Subject: [PATCH] fix(generate): improve error handling Deliver better errors than `Unexpected token } in JSON at position X` Fix issue #1047 https://github.com/nrwl/nx/issues/1047 --- .../workspace/src/schematics/remove/lib/update-tsconfig.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/workspace/src/schematics/remove/lib/update-tsconfig.ts b/packages/workspace/src/schematics/remove/lib/update-tsconfig.ts index dcfa74d631..e2b1a41a98 100644 --- a/packages/workspace/src/schematics/remove/lib/update-tsconfig.ts +++ b/packages/workspace/src/schematics/remove/lib/update-tsconfig.ts @@ -23,7 +23,12 @@ export function updateTsconfig(schema: Schema) { const tsConfigPath = 'tsconfig.json'; if (tree.exists(tsConfigPath)) { - let contents = JSON.parse(tree.read(tsConfigPath).toString('utf-8')); + let contents = tree.read(tsConfigPath).toString('utf-8'); + try { + contents = JSON.parse(contents); + } catch (e) { + throw new Error(`Cannot parse ${tsConfigPath}: ${e.message}`); + } delete contents.compilerOptions.paths[ `@${nxJson.npmScope}/${project.root.substr(5)}` ];