Skip to content

Commit

Permalink
fix(core): Fix the issue of nodes not loading when run via npx (#5888)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Apr 4, 2023
1 parent 695fabb commit 163446c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/cli/src/LoadNodesAndCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -117,8 +127,7 @@ export class LoadNodesAndCredentials implements INodesAndCredentials {
await writeStaticJSON('credentials', this.types.credentials);
}

private async loadNodesFromNodeModules(scanDir: string): Promise<void> {
const nodeModulesDir = path.join(scanDir, 'node_modules');
private async loadNodesFromNodeModules(nodeModulesDir: string): Promise<void> {
const globOptions = { cwd: nodeModulesDir, onlyDirectories: true };
const installedPackagePaths = [
...(await glob('n8n-nodes-*', { ...globOptions, deep: 1 })),
Expand Down

0 comments on commit 163446c

Please sign in to comment.