Skip to content

Commit f96f1ee

Browse files
committed
fix: Install node when npm/npx not found in getNpmCliToolExecutable
When npm/npx couldn't be found in any location (project, global, or alternative dir), getNpmCliToolExecutable would return an empty list. Flags like --no-update-notifier were then added to this empty list, resulting in a malformed command that tried to execute the flag as the program name. Added a fallback that triggers node installation when npm/npx is not found and an alternativeDirGetter is available. After installation, uses the paths from activeNodeInstallation which correctly point to the version-specific node installation directory (e.g., node-v24.10.0) rather than the old non-versioned 'node' directory.
1 parent d975ea2 commit f96f1ee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendTools.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,30 @@ private List<String> getNpmCliToolExecutable(BuildTool cliTool,
885885
forceAlternativeNode = true;
886886
}
887887

888+
// If npm/npx still not found, install node (which includes npm/npx)
889+
if (returnCommand.isEmpty() && alternativeDirGetter != null
890+
&& (cliTool.equals(BuildTool.NPM)
891+
|| cliTool.equals(BuildTool.NPX))) {
892+
forceAlternativeNodeExecutable();
893+
// After installation, activeNodeInstallation should be populated
894+
// with the correct paths for version-specific node installation
895+
ActiveNodeInstallation installed = activeNodeInstallation;
896+
if (installed != null && installed.npmCliScript() != null) {
897+
returnCommand = new ArrayList<>();
898+
returnCommand.add(installed.nodeExecutable());
899+
if (cliTool.equals(BuildTool.NPM)) {
900+
returnCommand.add(installed.npmCliScript());
901+
} else {
902+
// NPX is in the same directory as npm, just different
903+
// filename
904+
File npmCliFile = new File(installed.npmCliScript());
905+
File npxCliFile = new File(npmCliFile.getParentFile(),
906+
"npx-cli.js");
907+
returnCommand.add(npxCliFile.getAbsolutePath());
908+
}
909+
}
910+
}
911+
888912
if (flags.length > 0) {
889913
returnCommand = new ArrayList<>(returnCommand);
890914
Collections.addAll(returnCommand, flags);

0 commit comments

Comments
 (0)