1

Angular 10.2.2 version.

I have created Angular library my-lib using this page. In my library, I have devDependency on one of the internal NPM packages my-comp.web.

In my library I have imports like below

import { MyWebModule } from "my-comp.web/sdk/angular";
import { myWeb } from "my-comp.web/sdk";

If I build this library using ng build i.e. Ivy library, create its NPM package and then use this NPM package in another Angular Application, this Application's build works fine.

Now Angular recommends to build libraries with Ivy disabled, so when I build the same library code with ng build --prod and use this library in application, I get below error while building this application.

ERROR in The target entry-point "my-lib" has missing dependencies:
 - my-comp.web/sdk/angular
 - my-comp.web/sdk

Application's package.json has devDepencency of my-comp.web.

I have tried everything suggested on StackOverflow, including deleting node_modules and re-install it, but nothing is working. May I know what am I missing here ?

Sohan Soni
  • 1,207
  • 21
  • 35

1 Answers1

1

You should not be adding a dependency as the devDependency if it is required at runtime. npm documentation clearly states what devDependencies are for:

If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.

devDependencies are installed only if you don't pass --prod flag. So when you are building the application, it is failing because it doesn't have the dependencies/imports used in the library.

So I suggest you add the dependency as the peerDependency in your library and as a normal dependency in your application.

deepakchethan
  • 5,240
  • 1
  • 23
  • 33