簡體   English   中英

Nx - 使用運行命令生成器時出現“無法寫入引用...”錯誤

[英]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 不知道如何構建。

有兩個問題:

幸運的是,您可以正確配置工作區:

  1. 更新targetDependencies中的nx.json選項:

     "targetDependencies": { "build": [ { "target": "build", "projects": "dependencies" } ], "base-build": [ <== add this { "target": "base-build", "projects": "dependencies" } ] },
  2. 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"],

更新

我認為還有更好的方法:不要重命名常見目標buildlinttest等) ,而是只重命名您的自定義目標

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM