Sharing Code Modules via NPM


I’ve been asked by my client to take a substantial amount of my code base and make it shareable across the enterprise for future applications written using the ionic framework. I have researched and followed the examples of:

It seems like I almost had it working. At least no compile errors, but when running the app it crashes. I’ve tried so many different ways of exporting and importing but cannot get it to work.

What are the limitations with Ionic as far as sharing components, providers, classes, etc.? Are there any examples or documentation on creating large modules with many components and providers? Is it necessary to use symbolic NPM links for other than referencing code for workflow purposes? Do I need to package up my module for it work or can I use a file reference in my package.json?

Basically I just need to know if there are any limitations from Ionic’s perspective. I’ve hit the wall.


You can easily share components, providers, etc. Using an NgModule is the angular recommended way of doing so. I don’t think we have any documentation about large modules and best practices…yet.

For now, the best bet would be to create an package distributed over npm publicly or privately and have the module field in the package.json file point to the NgModule. It’s sort of complicated to make an Angular 3rd party library because you need to compile it with ngc, the angular ahead-of-time compiler.


I am already compiling the module using ngc and have that part working. For some reason, my consuming app sees the modules just fine but libraries that are just plain classes it is not working with correctly. I have a lot of base classes and although my code sees the file, it does not see the class so I cannot extend my child classes from the parents which are in the module. I get an error that says something about ‘any’ not being valid function for a constructor. I also cannot seem to use interfaces either.

If I was to put those inside the NgModule, where would they go? They are not components or providers.


This is the error I get:

type ‘any’ is not a constructor function type