New Vaadin 14 app fails to run, error “Failed to determine 'node' tool.” Missing Node.js and npm tools

后端 未结 6 1920
傲寒
傲寒 2020-12-03 15:25

I used the Get Started page to create a new Vaadin 14 app, after choosing the Plain Java Servlet option.

The web page successfully downloaded a .zip<

6条回答
  •  醉酒成梦
    2020-12-03 16:18

    The Problem is in method

    FrontendUtils::getNpmExecutable(String baseDir)

    from flow-server.jar. This method tries to locate

    node/node_modules/npm/bin/npm-cli.js

    in $baseDir (which is project root folder in case of prepare-frontend goal). When that path does not exist, code continues executing "where/which npm.cmd" to get absolute path of 'npm.cmd'. In my case, got NodeJS installed globally, it returns correct path.

    Subsequently code continues trying to execute "path-to-npm.cmd\npm.cmd -v", to ensure that npm.cmd exists and is runnable.

    And here is the problem in method:

    ProcessBuilder FrontEndUtils::createProcessBuilder(List command)

    In this method under certain circumstances program code sets environment variable 'PATH' to path of npm.cmd (since ProcssBuilder.environment() returns map which does not contain 'PATH' variable).

    Next when trying to execute command 'path-to-npm\npm.cmd -v', the exit value of the process is 1, and stderr is non-empty, because 'chcp' command is called before other stuff in 'npm.cmd' (probably SETLOCAL command), but since now 'chcp' is not in PATH.

    Following code evaluates these conditions (exit code 1, stderr nonempty) as an error in execution of npm.cmd and

    Failed to determine 'npm.cmd' tool.

    message is printed.

    This happens on my Windows 10, Vaadin Flow 14.0.1, NodeJS 10.16.3 installed globally.

    Also got the same issues when running tomcat server with an application, since $baseDir variable contains path to tomcat bin directory.

    Workaround

    As a workaround it is sufficient to make symbolic link of NodeJS directory into your project root (and if application running on Tomcat, also make link of NodeJS to Tomcat's bin directory).

提交回复
热议问题