Maven编译JHipster应用时路径多添加/node层的问题排查
问题解决:frontend-maven-plugin 错误拼接 Node 路径
问题根源
你配置的 <installDirectory> 指向了 Node 可执行文件所在的 bin 目录,但 frontend-maven-plugin 的 installDirectory 参数默认是Node 的根安装目录(即包含 bin 子目录的父目录)。插件会自动在该目录下拼接 /bin/node 定位可执行文件,所以当你把 installDirectory 设为 .../bin 时,最终路径就变成了 .../bin/node/node,导致找不到有效文件。
解决方案
有两种可行的配置方式,任选其一即可:
方式1:正确配置 installDirectory
将 installDirectory 改为 Node 的根目录(去掉末尾的 /bin),插件会自动在该目录的 bin 子目录下找到 Node 和 npm:
<plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <executions> <execution> <id>webapp build dev</id> <goals> <goal>npm</goal> </goals> <phase>generate-resources</phase> <configuration> <arguments>run webapp:build</arguments> <environmentVariables> <APP_VERSION>${project.version}</APP_VERSION> </environmentVariables> <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven> <!-- 修改为 Node 的根安装目录,去掉末尾的 /bin --> <installDirectory>/home/myuser/.nvm/versions/node/v16.17.0</installDirectory> </configuration> </execution> </executions> </plugin>
方式2:直接指定 Node 和 npm 的绝对路径
如果不想依赖插件的路径拼接逻辑,可以直接通过 <nodeExecutable> 和 <npmExecutable> 指定本地可执行文件的绝对路径,这种方式更直观:
<plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <executions> <execution> <id>webapp build dev</id> <goals> <goal>npm</goal> </goals> <phase>generate-resources</phase> <configuration> <arguments>run webapp:build</arguments> <environmentVariables> <APP_VERSION>${project.version}</APP_VERSION> </environmentVariables> <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven> <!-- 直接指定 Node 可执行文件路径 --> <nodeExecutable>/home/myuser/.nvm/versions/node/v16.17.0/bin/node</nodeExecutable> <!-- 直接指定 npm 可执行文件路径 --> <npmExecutable>/home/myuser/.nvm/versions/node/v16.17.0/bin/npm</npmExecutable> </configuration> </execution> </executions> </plugin>
验证配置
修改后重新运行 mvn clean compile,插件会直接调用你本地的 Node 和 npm,不会再尝试重新安装,也不会出现路径拼接错误。
内容的提问来源于stack exchange,提问作者chocalaca
相关产品推荐
相关产品推荐

