Koja
Koja

Reputation: 900

Nested Angular modules: Can't resolve service from npm package

I have an Angular 6 app that has the following nested module structure:

├── node_modules/
├── package.json <- no mention of ngx-cookie-service 
└── src/
    └── app/
        ├── app.module.ts
        └── sub-module/
            ├── node_modules/
            ├── package.json <- has dependency for ngx-cookie-service
            └── sub.module.ts

The purpose of this structure is that the submodule can be published as an npm package and the appmodule provides a website UI for using the submodule's functions.

I'm getting the following error when trying to run ng build --aot for the root project (appmodule):

ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'ngx-cookie-service/cookie- 
service/cookie.service' in 'myapp\src\app' 

Notes:

My first question is:

Is this a problem in my configuration or is it something about which I should contact the author of ngx-cookie-service?

And another folllow-up question:

How to resolve this error without adding a dependency for ngx-cookie-service in the root package.json? (Because that app doesn't itself need the cookie service, only the submodule needs it)

Upvotes: 0

Views: 1041

Answers (1)

Sheik Althaf
Sheik Althaf

Reputation: 1605

I suggest you to create a angular workspace where you can able to create multiple libraries and Applications. https://angular.io/guide/workspace-config

Pros

  • You can able to publish your library to npm
  • you can share that library with your apps in a workspace.

read this post for better understanding

https://blog.angularindepth.com/angular-workspace-no-application-for-you-4b451afcc2ba

Upvotes: 1

Related Questions