使用 NX 命令创建角度库时出现 SchematicsException

Fra*_*sco 5 angular-cli angular nrwl-nx

我将 NX 工作区更新到最新版本 ( "@nrwl/angular": "11.5.2"),将其与 monorepo 中的 Angular 应用程序 (v 11.2.6) 结合使用。

我想使用以下命令生成一个新的 Angular 库:

ng generate @nrwl/angular:library --name=service --style=scss --directory=/libs/booking
Run Code Online (Sandbox Code Playgroud)

但我在控制台中收到以下错误:

SchematicsException [Error]: Project name "-libs-booking-service" is not valid.
New project names must start with a letter, and must contain only alphanumeric 
characters or dashes. When adding a dash the segment after the dash must also
start with a letter.
Run Code Online (Sandbox Code Playgroud)

该命令以某种方式在项目名称之前添加了一个破折号-,从而生成错误。

我还清除了node_modules并再次重新安装了软件包,但没有任何运气。


更新

在 Shashank 的提示后,我在下面留下了帮助我解决问题的步骤:

如果我删除目录参数中的前导/,则会收到以下错误:

ng generate @nrwl/angular:library --name=services --style=scss --directory=libs/booking

TypeError: Cannot read property 'paths' of undefined
Run Code Online (Sandbox Code Playgroud)

这是由于 tsconfig.json 对于 NX 来说应该仍然是tsconfig.base.json。通过(暂时)重命名该命令即可运行。

Sha*_*vek 2

根据您的评论,我认为以下命令适合您。您的directoryhad /libs/booking,应该是libs/booking

ng generate @nrwl/workspace:library --name=service --style=scss --directory=libs/booking
Run Code Online (Sandbox Code Playgroud)