You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle vaadinBuildFrontend任务并行执行时偶现pnpm失败咨询

vaadinBuildFrontend任务多模块并行执行问题解答

核心问题

执行Gradle的vaadinBuildFrontend任务时,启用--parallel选项会偶尔出现pnpm相关失败,禁用并行后问题消失,询问该任务是否支持多模块并行执行。

错误日志

> Task :web-locker:vaadinBuildFrontend FAILED
version check '/usr/bin/npx --yes --quiet pnpm' failed
com.vaadin.flow.server.frontend.FrontendUtils$UnknownVersionException: Unable to detect version of pnpm. Using command /usr/bin/npx --yes --quiet pnpm --version
    at com.vaadin.flow.server.frontend.FrontendUtils.getVersion(FrontendUtils.java:1051)
    at com.vaadin.flow.server.frontend.FrontendTools.validatePnpmVersion(FrontendTools.java:1104)
    at com.vaadin.flow.server.frontend.FrontendTools.getSuitablePnpm(FrontendTools.java:1090)
    at com.vaadin.flow.server.frontend.TaskRunNpmInstall.createPnpmFile(TaskRunNpmInstall.java:529)
    at com.vaadin.flow.server.frontend.TaskRunNpmInstall.runNpmInstall(TaskRunNpmInstall.java:304)
    at com.vaadin.flow.server.frontend.TaskRunNpmInstall.execute(TaskRunNpmInstall.java:183)
    at com.vaadin.flow.server.frontend.NodeTasks.execute(NodeTasks.java:342)
    at com.vaadin.flow.plugin.base.BuildFrontendUtil.runNodeUpdater(BuildFrontendUtil.java:343)
    at com.vaadin.gradle.VaadinBuildFrontendTask.vaadinBuildFrontend(VaadinBuildFrontendTask.kt:71)

...

    at java.base@11.0.15/java.lang.Thread.run(Thread.java:829)
Caused by: com.vaadin.flow.server.frontend.FrontendUtils$CommandExecutionException: Process execution failed with exit code 217
Output: 
Error output: npm WARN cleanup Failed to remove some directories [
npm WARN cleanup   [
npm WARN cleanup     undefined,
npm WARN cleanup     TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
npm WARN cleanup         at rm (node:internal/fs/promises:679:38)
npm WARN cleanup         at /usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:553:20
npm WARN cleanup         at Array.map (<anonymous>)
npm WARN cleanup         at [rollbackCreateSparseTree] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:553:8)
npm WARN cleanup         at [reifyPackages] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:256:31)
npm WARN cleanup         at async Arborist.reify (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:170:5)
npm WARN cleanup         at async exec (/usr/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:264:7)
npm WARN cleanup         at async module.exports (/usr/lib/node_modules/npm/lib/cli.js:134:5) {
npm WARN cleanup       code: 'ERR_INVALID_ARG_TYPE'
npm WARN cleanup     }
npm WARN cleanup   ]
npm WARN cleanup ]
npm ERR! code ENOTEMPTY
npm ERR! syscall rmdir
npm ERR! path /root/.npm/_npx/e6e0ed1aca658cae/node_modules/pnpm/dist/node_modules/node-gyp/gyp
npm ERR! errno -39
npm ERR! ENOTEMPTY: directory not empty, rmdir '/root/.npm/_npx/e6e0ed1aca658cae/node_modules/pnpm/dist/node_modules/node-gyp/gyp'
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-09-27T09_19_32_771Z-debug-0.log
    at com.vaadin.flow.server.frontend.FrontendUtils.executeCommand(FrontendUtils.java:1083)
    at com.vaadin.flow.server.frontend.FrontendUtils.getVersion(FrontendUtils.java:1048)
    ... 136 more

解答

vaadinBuildFrontend任务不支持多模块并行执行,原因如下:

  • 该任务依赖的前端工具链(pnpm/npx)会使用全局共享的缓存目录(比如日志中的/root/.npm/_npx),当多个模块并行执行该任务时,会出现多个进程同时读写、修改该缓存目录的情况,引发文件锁冲突、目录删除失败等竞争错误(日志中的ENOTEMPTY错误就是典型的并行资源竞争表现)。
  • Vaadin官方默认将该任务标记为非并行安全,Gradle并行模式下多模块同时执行会触发这类不可预期的失败。

解决办法

  • 最稳妥的方式是保持禁用Gradle的--parallel选项;
  • 若必须使用并行,可尝试为每个模块配置独立的前端缓存目录:比如通过设置pnpm的store-dir参数,或在Gradle配置中为每个模块的vaadin扩展指定独立的nodeOptions来隔离缓存,但这种配置复杂度较高,需要针对每个模块单独调整。

内容的提问来源于stack exchange,提问作者Martin Ahrer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 02:34:50