如果在使用NX进行开发时出现了“Angular cannot find shared component in NX”的问题,可能需要遵循以下步骤:
首先,确保该共享组件位于与使用它的项目不同的Nx workspace中。例如,一个共享组件库位于libs / ui / components中,而使用它的项目位于apps / my-app中。
在使用共享组件的项目中的app.module.ts文件中添加共享组件库的引用。示例代码如下:
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NxModule } from '@nrwl/nx';
import { MyComponent } from '../../../../libs/ui/components/src/lib/my-component/my-component.component';
@NgModule({
imports: [
NxModule.forRoot()
],
declarations: [
AppComponent,
MyComponent
],
bootstrap: [AppComponent]
})
export class AppModule {}
"compilerOptions": {
...
"paths": {
"@my-org/ui-components": [
"libs/ui/components/src/index.ts"
]
}
}
这应该解决“Angular cannot find shared component in NX”问题。