[英]Nx - 'Unable to write a reference...' error when using run-commands builder
我在構建一個依賴於同一 Nx 工作區中的另一個庫的庫時遇到了一個特殊錯誤。 我正在使用運行命令構建器,因為在初始庫構建之后需要調用其他一些任務。
我看到“無法編寫參考...”類型錯誤消息,例如
Unable to write a reference to SomethingCoolComponent in /Users/robert.parker/Documents/Github/nx-playground/libs/common-components/src/lib/components/something-cool/something-cool.component.ts from /Users/robert.parker/Documents/Github/nx-playground/libs/common-components/src/lib/common-components.module.ts
ERROR: Something went wrong in @nrwl/run-commands - Command failed: nx base-build shiny-components
我有一個可復制的倉庫,我可以在這里展示https://github.com/parky128/nx-playground使用幾個最小的庫,兩者之間存在依賴關系。
安裝依賴項后,只需運行ng run shiny-components:build
並查看發出的錯誤。
如果我不使用run-commands
構建器,而只是在同一個庫上運行ng run shiny-components:base-build
任務,它構建得很好,所以我責怪 run-commands 但我不確定它為什么會中斷。
我已經看到與同一問題相關的這個答案,盡管他們似乎沒有使用運行命令並且對他們來說歸結為路徑導入問題,但我認為這不是我的問題的原因。
這里的問題是您引入了一個全新的目標名稱base-build
,而 nx 不知道如何構建。
有兩個問題:
nx 無法構建正確的依賴關系圖https://github.com/nrwl/nx/blob/75e6b125351ca828021302b8aef838709be3d579/packages/workspace/src/tasks-runner/utils.ts#L26-L52
nx 無法為依賴庫 https 正確准備tsconfig.compilerOptions.paths
://github.com/nrwl/nx/blob/1139c616e1b7e27c519e385a3982ac8b486dbb0f/packages/workspace/src/utilities/buildable-libs-util#L11
幸運的是,您可以正確配置工作區:
更新targetDependencies
中的nx.json
選項:
"targetDependencies": { "build": [ { "target": "build", "projects": "dependencies" } ], "base-build": [ <== add this { "target": "base-build", "projects": "dependencies" } ] },
為angular.json
中的 common-components 重命名或引入相同的目標名稱:
"common-components": { "projectType": "library", "root": "libs/common-components", "sourceRoot": "libs/common-components/src", "prefix": "rob", "architect": { "base-build": { <========================= this line "builder": "@nrwl/angular:package", "outputs": ["dist/libs/common-components"],
我認為還有更好的方法:不要重命名常見目標( build
、 lint
、 test
等) ,而是只重命名您的自定義目標
angular.json
"build-with-task": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
"nx build shiny-components",
"echo done"
],
現在,您應該能夠運行以下命令之一:
ng run shiny-components:build
ng run shiny-components:build-with-task
這是您的 repo https://github.com/parky128/nx-playground/pull/1/files的最終 PR
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.