From 163446c674d07c060eaa0d7ec54a087a4cb671d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 3 Apr 2023 12:14:41 +0200 Subject: [PATCH] fix(core): Fix the issue of nodes not loading when run via npx (#5888) --- packages/cli/src/LoadNodesAndCredentials.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/LoadNodesAndCredentials.ts b/packages/cli/src/LoadNodesAndCredentials.ts index 8048673425728..47623076c4ff6 100644 --- a/packages/cli/src/LoadNodesAndCredentials.ts +++ b/packages/cli/src/LoadNodesAndCredentials.ts @@ -67,9 +67,19 @@ export class LoadNodesAndCredentials implements INodesAndCredentials { this.downloadFolder = UserSettings.getUserN8nFolderDownloadedNodesPath(); // Load nodes from `n8n-nodes-base` and any other `n8n-nodes-*` package in the main `node_modules` - await this.loadNodesFromNodeModules(CLI_DIR); - // Load nodes from installed community packages - await this.loadNodesFromNodeModules(this.downloadFolder); + const pathsToScan = [ + // In case "n8n" package is in same node_modules folder. + path.join(CLI_DIR, '..'), + // In case "n8n" package is the root and the packages are + // in the "node_modules" folder underneath it. + path.join(CLI_DIR, 'node_modules'), + // Path where all community nodes are installed + path.join(this.downloadFolder, 'node_modules'), + ]; + + for (const nodeModulesDir of pathsToScan) { + await this.loadNodesFromNodeModules(nodeModulesDir); + } await this.loadNodesFromCustomDirectories(); await this.postProcessLoaders(); @@ -117,8 +127,7 @@ export class LoadNodesAndCredentials implements INodesAndCredentials { await writeStaticJSON('credentials', this.types.credentials); } - private async loadNodesFromNodeModules(scanDir: string): Promise { - const nodeModulesDir = path.join(scanDir, 'node_modules'); + private async loadNodesFromNodeModules(nodeModulesDir: string): Promise { const globOptions = { cwd: nodeModulesDir, onlyDirectories: true }; const installedPackagePaths = [ ...(await glob('n8n-nodes-*', { ...globOptions, deep: 1 })),