gonzofish / angular-librarian

An Angular 2+ scaffolding setup for creating libraries
https://www.npmjs.com/package/angular-librarian
MIT License
91 stars 9 forks source link

ng serve command is broken after installing package created by angular-librarian #51

Closed stevermeister closed 7 years ago

stevermeister commented 7 years ago

not sure whether it's a bug of angular-librarian, but decided to report it also here to let you know https://github.com/angular/angular-cli/issues/6961

gonzofish commented 7 years ago

That's very strange--I'll try setting up a project myself and seeing what happens

gonzofish commented 7 years ago

it looks like the CLI changed how they're handling packages in 1.2 so I think what's happening is that installing a 3rd party package installs the @angular/* packages more than once as far as the CLI can tell

gonzofish commented 7 years ago

I ran npm install inside myapp and everything seemed to work after that

stevermeister commented 7 years ago

even after npm install does not work for me :(

gonzofish commented 7 years ago

you're getting the same error?

stevermeister commented 7 years ago

just removed everything and did with npm install - and now it works, weird..

stevermeister commented 7 years ago

ok, now I got something else when try to include the module:

AngularSwitcheryModule is not an NgModule

gonzofish commented 7 years ago

Yeah I did too, try doing AngularSwitcheryModule.forRoot() on the import

stevermeister commented 7 years ago

sorry, my bad, true

stevermeister commented 7 years ago

now something new:

ERROR in Error encountered resolving symbol values statically. Calling function 'AngularSwitcheryMo
dule', function calls are not supported. Consider replacing the function or lambda with a reference
 to an exported function, resolving symbol AppModule in /Users/stevermeister/workspace/research/swt
tt/src/app/app.module.ts, resolving symbol AppModule in /Users/stevermeister/workspace/research/swt
tt/src/app/app.module.ts
gonzofish commented 7 years ago

Weird, I didnt get that. Can I see your app.module.ts?

stevermeister commented 7 years ago
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularSwitcheryModule } from 'angular-switchery';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AngularSwitcheryModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
stevermeister commented 7 years ago

and the most weird thing: when I remove line

 AngularSwitcheryModule.forRoot()

it works and when I return it back (without stoping ng serve) it works!!!!

BUT when I stop ng serve and try to run it again - same error

gonzofish commented 7 years ago

Interesting...still looking into it

gonzofish commented 7 years ago

I'm not sure if this is looking like something the library is doing wrong...

This issue against the CLI has devs complaining of the same problem.

stevermeister commented 7 years ago

Yes, I also find this thread. Is there a way to reproduce it without publishing? Basically to run compiled version

gonzofish commented 7 years ago

Further investigation led to this answer by @trekhleb which led to this answer by @SebastianSchenk

So I'm not sure what to think...

gonzofish commented 7 years ago

So...that error doesn't have a big effect on running ng serve after the initial pass.

Basically, as you said, @stevermeister, if you just save a file for a second time, it'll recompile no problem...this is a really odd problem.

gonzofish commented 7 years ago

Quick question, @stevermeister, what OS are you using?

stevermeister commented 7 years ago

macOS Sierra

all information about env is provided here - https://github.com/angular/angular-cli/issues/6961

gonzofish commented 7 years ago

Well there goes that theory 😢

Still trying to parse it out...

gonzofish commented 7 years ago

Just a "update":

  1. I've seen answers from Angular team members saying to others that the metadata isn't being provided or its bad--but from any comparison I do (such as to the Angular Material outputs), everything looks correct.
  2. I'm really down in the weeds on the CLI trying to figure this out, I'm looking at the spot where the compiler tries to gather info about our module.
  3. This feels a bit insane to be doing.
gonzofish commented 7 years ago

I may have figured it out! I think its two-fold:

  1. The types attribute in package.json should be typings
  2. The value for that attribute should be ./[your package].d.ts not ./index.d.ts

So (and you can do this from within your Angular CLI app), modify the package.json of your library so that the line:

  "types": "./index.d.ts",

becomes:

  "typings": "./angular-switchery.d.ts",

And let me know if that fixes anything...

gonzofish commented 7 years ago

I published my test library for Angular librarian with the changes and it seems to be working.

It also makes it so you don't have to do .forRoot(), unless you need to.

gonzofish commented 7 years ago

@stevermeister, I'll leave this to you to close. You can do so by updating to the latest version, if need be.

Link to latest release

stevermeister commented 7 years ago

@gonzofish it works! thank you very much! sorry for delay, did not have time to check and update the app.

gonzofish commented 7 years ago

Excellent! I'll merge it in when I finish up the testing branch I thought this was a different issue 😄