执行nx build命令失败,报TypeError: 无法读取undefined的'cloud'属性
解决 nx build 时的 "Cannot read properties of undefined (reading 'cloud')" 错误
可能的原因与修复步骤
检查 nx-cloud 版本兼容性
该错误多因 nx-cloud 与当前 Nx 版本不匹配引发。先查看项目 Nx 版本:nx --version安装与 Nx 版本匹配的 nx-cloud 包:
npm install @nrwl/nx-cloud@<对应版本号> --save-dev或直接安装最新兼容版本:
npm install @nrwl/nx-cloud@latest --save-dev清除依赖与构建缓存
- 删除依赖目录与锁文件:
rm -rf node_modules package-lock.json yarn.lock - 重新安装依赖:
npm install - 重置 Nx 构建缓存:
nx reset
- 删除依赖目录与锁文件:
校验配置文件中的任务 runner 配置
检查workspace.json或nx.json里的tasksRunnerOptions配置,确保 nx-cloud runner 参数传递正确。示例配置:{ "tasksRunnerOptions": { "default": { "runner": "@nrwl/nx-cloud", "options": { "cacheableOperations": ["build", "test", "lint"], "accessToken": "<你的访问令牌>" } } } }若无需 nx-cloud,可临时切换回默认 runner:
{ "tasksRunnerOptions": { "default": { "runner": "@nrwl/workspace/tasks-runners/default", "options": { "cacheableOperations": ["build", "test", "lint"] } } } }临时禁用 nx-cloud 执行
运行构建命令时添加参数跳过 nx-cloud:nx build --cloud=false
内容的提问来源于stack exchange,提问作者Vivek Maru
相关产品推荐
相关产品推荐

