NX affected命令build正常但release无项目运行的问题排查
问题原因及解决办法
核心原因
你执行npx nx affected --target=release时出错,本质是**release并非项目级别的可执行target**:
nx affected --target=<target>用于触发项目project.json中明确定义的target(比如build、test这类),但你提供的ds-components的project.json里完全没配置release这个target,所以NX找不到可执行的目标。- 而
nx affected:build能正常运行,是因为build是NX为库项目默认生成的target,或是你已在项目/全局配置中定义过它。
另外,你在workspace配置里的release块,是NX Release插件的全局规则配置,并非供nx affected调用的项目target,二者不属于同一概念范畴。
正确处理方式
要针对变更项目执行发布,需使用NX Release插件的专用命令:
npx nx release affected --base=origin/develop --exclude='storybook-host' --verbose
如果需要自定义发布流程,你得先在项目的project.json中添加release target,示例如下:
// packages/ds-components/project.json { "name": "ds-components", // ... 其他原有配置 "targets": { "release": { "executor": "nx:run-commands", "options": { "commands": [ "nx build {projectName}", "nx nx-release-publish {projectName}" ] } } } }
完成配置后,再执行npx nx affected --target=release --base=origin/develop --exclude='storybook-host' --verbose即可正常运行。
内容的提问来源于stack exchange,提问作者Maurice
相关产品推荐
相关产品推荐

