2 years ago
#59567

Happy Coder
Angular could not find module when using libraries
I am using angular libraries and have the following structure
.
└── MyAngularProject/
├── projects/
│ └── my-project-name-here/
│ └── src/
│ ├── modules/
│ │ ├── module1/
│ │ │ ├── components1/
│ │ │ ├── components2/
│ │ │ ├── components3/
│ │ │ ├── module1.module.ts
│ │ │ └── module1-routing.module.ts
│ │ └── module2/
│ │ ├── components1/
│ │ ├── components2/
│ │ ├── components3/
│ │ ├── module2.module.ts
│ │ └── module2-routing.module.ts
│ ├── my-project.module.ts
│ ├── my-project-routing.module.ts
│ └── my-project.component.ts
├── src/
│ ├── app/
│ │ ├── app.component.html
│ │ ├── app.module.ts
│ │ └── app-routing.module.ts
│ ├── index.html
│ ├── environments/
│ └── pollyfills.ts
├── angular.json
├── tsconfig.json
└── tsconfig.app.json
Now I am using the following command to build the libraries before I run the project
ng build --project my-project-name-here --watch
and then I am starting the app with npm start
.
Now when I run this for the first time, I am seeing an error that says
ERROR in Could not resolve module ./modules/module1/module1.module relative to dist/my-project-name-here/my-project-name.d.ts
If I save something there in the project/modules, it will again rebuild and this error will be gone. But now when I try to access a page in the browser using routes, it shows that Cannot find module './modules/module1/module1.module'
and the page will be redirected to localhost:4002
. I am not using the app routes actually and all the routes specified in the project's route and in corresponding routes for modules. This might work at times, but if I stop the build command and run it again, it is again showing the same error. How can I fix this once and for all?
I am using Angular 8 and the project route structure in like
const routes: Routes = [
{
path: 'my-path',
component: MainLayoutComponent,
children: [
{
path: 'list',
loadChildren: './modules/module1/module1.module#ModuleNameModule'
}
]
}
];
Also npm start
runs the ng serve
command
angular
angular8
angular-library
0 Answers
Your Answer