AhsanAyaz / ngx-device-detector

An Angular v7+ library to detect the device, OS, and browser details.
https://ahsanayaz.github.io/ngx-device-detector
MIT License
521 stars 101 forks source link

AOT compiler - Unexpected value 'Ng2DeviceDetector in ng2-device-detector/dist/index.d.ts #6

Closed slav-pilus closed 7 years ago

slav-pilus commented 7 years ago

I'm getting Unexpected value 'Ng2DeviceDetector in [...]/node_modules/ng2-device-detector/dist/index.d.ts' imported by the module 'AppModule in [...]/app/app.module.ts'. Please add a @NgModule annotation.

while compiling with aot compiler using: ./node_modules/.bin/ngc -p tsconfig-aot.json everything works just fine with regular ts compiler. It this a bug or am I missing something?

my component:

import {Component} from "@angular/core";
import {Device} from "ng2-device-detector";

@Component({
    selector: "device-info",
    template: `
        <div id="deviceInfo">
        </div>
    `
})
export class DeviceInfoComponent{

    constructor(private device: Device) {
        this.test();
    }

    test() {
        console.log(this.device.browser);
        console.log(this.device.browser_version);
        console.log(this.device.device);
        console.log(this.device.isDesktop());
        console.log(this.device.isMobile());
        console.log(this.device.isDesktop());
    }
}

my app.module.ts

[...]
import {Device, Ng2DeviceDetector} from "ng2-device-detector";

@NgModule({
  imports:      [
      [...]
      Ng2DeviceDetector
  ],
  declarations: [
     [...]
      DeviceInfoComponent,
  ],
  providers: [
      [...]
      Device,
  ],
  bootstrap:    [
      CheckoutComponent
  ]
})
export class AppModule {
    constructor(ngCartRedux: NgRedux<ICartState>) {
        ngCartRedux.provideStore(cartStore)
    }
}
  bootstrap:    [
      CheckoutComponent
  ]
})
export class AppModule {
    constructor(ngCartRedux: NgRedux<ICartState>) {
        ngCartRedux.provideStore(cartStore)
    }
}
sushruth commented 7 years ago

I too am getting the same error.

sushruth commented 7 years ago

@slavP I have a fix for this and I have created a pull request for this. Can you help me confirm if the pull request fixes your issue ? to confirm, you will have to remove this plugin from your project and then install the forked version in your project using this command :

npm install Cachy/ng2-device-detector

and then try to build your code to see if you still get the error or not. Share your results here in either case.

slav-pilus commented 7 years ago

@sushruth The forked version does solve the issue for me

sushruth commented 7 years ago

@slavP Thanks for verifying.

AhsanAyaz commented 7 years ago

Pull request 7 seems to have resolved this issue