filipesilva / angular-quickstart-lib

MIT License
305 stars 75 forks source link

How to properly consume the lib in another app? #1

Closed pjmolina closed 7 years ago

pjmolina commented 7 years ago

Hi Filipe! Thanks for providing this quickstart for building libs. I am build an ng lib following your quickstart.

How to properly consume the lib in another app?

I am doing the install the app as follows:

npm install ../lib4 --save

Then, in the main module, doing the import in this way:

import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { LibModule } from 'lib4/dist/lib4';  // Import lib

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...
    LibModule  
  ],
  providers: [],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

This results in the following error on build stage:

ERROR in Error encountered resolving symbol values statically. Could not resolve lib4/dist/lib4 relative to C:/dev/appProject/src/app/app.module.ts., resolving symbol AppModule in C:/dev/appProject/src/app/app.module.ts, resolving symbol AppModule in C:/dev/appProject/src/app/app.module.ts

ERROR in C:/dev/appProject/src/app/app.module.ts (7,27): Cannot find module 'lib4/dist/lib4'.)

I tried importing the dist/ files and also the bundles/ versions having similar errors in either cases.

Environment used: the app is built using angular-cli based (v. 1.0.0.-rc.2) plus angular v.2.4.9, node 7.7.2 on Windows 10.

Thanks!

filipesilva commented 7 years ago

Whoa wait, this isn't ready yet! I'm still iterating on the setup. As far as I can tell, there's actually a bug with ngc on windows that causes that problem: https://github.com/angular/angular/issues/15192

When this is ready, it'll be up on angular.io though, with full instructions.