Nrwl Nx生成服务而不是lib吗?

时间:2018-07-29 02:35:54

标签: angular-cli nrwl

在我的Nx工作区的根目录中,当我运行命令ng g lib my-lib时,它将在MyLibService文件夹中生成名为myLib/src/libs服务 >我的工作区的根。我希望它在 libs 文件夹(libs/my-lib/src)内创建一个新的 lib 。 (在升级到v6之前,它曾经这样做。)

此外,创建服务后,什么都不会添加到我的angular.json文件中。

因此至少有三件事出了错:

  1. 生成工件的路径错误。
  2. 它正在生成service而不是lib
  3. angular.json中没有任何记录

我在做什么错了?

谢谢。

更新#1

我创建了一个新的测试工作区,添加了一个应用程序,并使用与上述相同的命令向其中添加了一个lib。一切都按预期工作,所以我认为这意味着我的环境(包装等)是正确的。我比较了虚拟工作空间和我的真实工作空间的angular.json文件,发现我的真实工作空间缺少一个似乎相关的条目:"defaultCollection": "@nrwl/schematics"

我添加了该条目,现在,当我尝试创建一个lib时,它将停留10-15秒,然后报告:

ERROR! test2/karma.conf.js does not exist..
ERROR! test2/ng-package.json does not exist..
ERROR! test2/ng-package.prod.json does not exist..
ERROR! test2/package.json does not exist..
ERROR! test2/tsconfig.lib.json does not exist..
ERROR! test2/tsconfig.spec.json does not exist..
ERROR! test2/tslint.json does not exist..
ERROR! test2/src/test.ts does not exist..
ERROR! test2/src/index.ts does not exist..
ERROR! test2/src/lib/test2.component.ts does not exist..
ERROR! test2/src/lib/test2.module.ts does not exist..
ERROR! libs/test2/src/lib/test2.module.ts does not exist..
ERROR! libs/test2/src/index.ts does not exist..
ERROR! libs/test2/tsconfig.lib.json does not exist..
ERROR! libs/test2/tsconfig.spec.json does not exist..
ERROR! libs/test2/tslint.json does not exist..
ERROR! libs/test2/karma.conf.js does not exist..
The Schematic workflow failed. See above.

'test2'是我尝试创建的库的名称

现在,任何地方都不会创建任何东西,并且我的angular.json不会被修改。

我将继续对此进行研究。

1 个答案:

答案 0 :(得分:0)

已解决。我将实际工作区package.json中的所有软件包版本重置为有效的package.json的版本(通常为Angular 6.0.1)。清除了我的node_modules文件夹并开始纱。现在一切正常。

在Nrwl / Nx GitHub存储库上的一个无关问题上,Victor Savkin评论说,直到Nx 6.2才支持Angular 6.1。

经验教训:除非您有特定的升级理由,否则请不要总是将事物的最新版本更新...请稍等片刻,并保留一两个版本!