From 7d797b008e1851425e61830ace6a698dd8dcf692 Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Tue, 21 Dec 2021 09:19:03 -0500 Subject: [PATCH] fix: fallback to built in nx utils if required function doesnt exist --- apps/vscode/src/main.ts | 2 +- .../nx-workspace/src/lib/get-nx-workspace-package.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/vscode/src/main.ts b/apps/vscode/src/main.ts index ecd8fa75de..128d1f1f33 100644 --- a/apps/vscode/src/main.ts +++ b/apps/vscode/src/main.ts @@ -146,7 +146,7 @@ export async function activate(c: ExtensionContext) { getOutputChannel().appendLine( 'Nx Console encountered an error when activating' ); - getOutputChannel().appendLine(JSON.stringify(e)); + getOutputChannel().appendLine(e.stack); getTelemetry().exception(e.message); } } diff --git a/libs/vscode/nx-workspace/src/lib/get-nx-workspace-package.ts b/libs/vscode/nx-workspace/src/lib/get-nx-workspace-package.ts index b85d10e5a4..1dc7b06d44 100644 --- a/libs/vscode/nx-workspace/src/lib/get-nx-workspace-package.ts +++ b/libs/vscode/nx-workspace/src/lib/get-nx-workspace-package.ts @@ -33,12 +33,19 @@ export async function getNxWorkspacePackageFileUtils(): Promise< importPath = importPath.replace(/\\/g, '/'); } const imported = __non_webpack_require__(importPath); + + if (!('readWorkspaceConfig' in imported)) { + throw new Error( + 'Workspace tools does not have `readWorkspaceConfig` function. Use built in @nrwl/workspace package' + ); + } + return res(imported); } catch (error) { getOutputChannel().appendLine( ` Error loading @nrwl/workspace from workspace. Falling back to extension dependency - Error: ${error} + ${error} ` ); return res(NxWorkspaceFileUtils);