Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing metadata.json files for AoT compilation #223

Closed
dagstuan opened this issue Sep 9, 2016 · 13 comments
Closed

Missing metadata.json files for AoT compilation #223

dagstuan opened this issue Sep 9, 2016 · 13 comments

Comments

@dagstuan
Copy link

dagstuan commented Sep 9, 2016

Currently the library does not support AoT compilation due to missing metadata.json files that need to be included along with d.ts-files.

See:

https://github.com/orizens/angular2-infinite-scroll/issues/77#issuecomment-245027350
angular/angular#11262 (comment)
angular/angular#11262 (comment)

@e-schultz
Copy link
Member

Looking into getting AoT support in soon, and how this works with the @select decorator - have been running into some issues with that, and would like to get that resolved soon as AoT will be important for many projects.

Thanks for letting us know about the metadata.json / links to other issues - will try and get this resolved soon.

e-schultz added a commit that referenced this issue Sep 21, 2016
* Start adding support for AoT
* Add dev dependencies for angular compiler
* Update tsconfig to tell ngc to emit metadata
@duydao
Copy link

duydao commented Oct 5, 2016

Thanks for looking into this! In the meantime, is there any workaround for this issue?

@h2qutc
Copy link

h2qutc commented Oct 6, 2016

Hi, did anyone fix this issue ?

@e-schultz
Copy link
Member

Been busy traveling for work lately and haven't had as much time to work on this, but have a test module published at 4.0.0-aotbeta.3 - still not fully working.

One error once I've gotten past the NgModule error, is how it behaves when you pass functions into selectors.

export const stuffSelect = n=>n.tuff;
export class Stuff {
  @select(n=>n.stuff) thisWillCauseAnError$
  @select(stuffSelect) thisWilNotCauseAnError$
}

If anyone has a demo repo with an AoT app working that they could point me at to help play around with as a test bed, that would be great.

@e-schultz
Copy link
Member

Some update/progress:

Working on a repo with master of angular-cli.

e-schultz/ng2-redux-aot-example#1

Have it so things don't throw errors, however the @select decorator just fails to work, will investigate further.

@hasangilak
Copy link

i had this problem with ngc over NgRedux error which could be handle like this
you can safely add ReduxWrapper as a provider to NgModule now

 import {Injectable} from "@angular/core";
 import {NgRedux} from "ng2-redux/lib/index";
 import {IAppState} from "./../store/store";

 @Injectable()
 export class ReduxWrapper {
      private redux: NgRedux<IAppState>;

      constructor() {
        this.redux = new NgRedux<IAppState>();
      }
 }

@hasangilak
Copy link

also there must be another work around for combineReducers function . this style ditch the error of re-exporting Reducer over ngc compilation
<Reducer<IAppState>>combineReducers<IAppState>

@hasangilak
Copy link

also there is a problem with redux library which throws an error on NODE_ENV === "productions". no way to handle this ...

e-schultz added a commit that referenced this issue Oct 19, 2016
* Start adding support for AoT
* Add dev dependencies for angular compiler
* Update tsconfig to tell ngc to emit metadata

Sorry for the delay on this, was hoping to get AoT working for
decorators also - but there seems to be some challenges around that.

* Update build to use ngc - metadata.json is now produced
* Fix `Unexpected value 'NgReduxModule' imported`
* NgReduxModule

```js
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NgReduxModule, NgRedux } from 'ng2-redux';
import { IAppState } from './appstate';
import { rootReducer } from './store';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    NgReduxModule.forRoot(),
    BrowserModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
  constructor(ngRedux: NgRedux<IAppState>) {

    ngRedux.configureStore(rootReducer,{});
  }
}

```

The DevTools provider is not provider by default with the
`NgReduxModule`, as you may not want to include this for production
builds. To use `DevToolsExtension`, it is the same as before - and still
need to include it in your providers.

```js
import { NgReduxModule, DevToolsExtension }

@NgModule({
  providerS: [DevToolsExtension]
})
export class AppModule {
  constructor(ngRedux:NgRedux<IAppState>, devTools:DevToolsExtension) {
    // config as before
  }
}
```

**IMPORTANT NOTE ABOUT AOT**

If using the ngc compiler and AoT compilation - `@select` decorators
will not work. If you want to use the ngc compiler (either directly, or
via angular-cli), and want to use the `@select` - you will need to use
the `--aot false` flag.

If you want to use AoT - the build process will work, but decorators
will silently stop working. If you want to use AoT.

**before**

```js
import { select } from 'ng2-redux';
export class MyComponent {
  @select() thing$:Observable<string>;
}
```

**after**

```js
import { NgRedux } from 'ng2-redux';
export class MyComponent {
  thing$:Observable<string>;
  constructor(private ngRedux:NgRedux<MyAppState>) {

  }
  ngOnInit() {
    this.thing$ = this.ngRedux.select (n => n.thing);
  }
}
```

We are big fans of how the `@select` works - and high priority to get
this working, but it seems to possibly be a limitation of the compiler.
Any feedback / help / suggestions to try and get this working with AoT
would be greatly appreciated.
e-schultz added a commit that referenced this issue Oct 19, 2016
* Start adding support for AoT
* Add dev dependencies for angular compiler
* Update tsconfig to tell ngc to emit metadata

Sorry for the delay on this, was hoping to get AoT working for
decorators also - but there seems to be some challenges around that.

* Update build to use ngc - metadata.json is now produced
* Fix `Unexpected value 'NgReduxModule' imported`
* NgReduxModule

```js
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NgReduxModule, NgRedux } from 'ng2-redux';
import { IAppState } from './appstate';
import { rootReducer } from './store';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    NgReduxModule.forRoot(),
    BrowserModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
  constructor(ngRedux: NgRedux<IAppState>) {

    ngRedux.configureStore(rootReducer,{});
  }
}

```

The DevTools provider is not provider by default with the
`NgReduxModule`, as you may not want to include this for production
builds. To use `DevToolsExtension`, it is the same as before - and still
need to include it in your providers.

```js
import { NgReduxModule, DevToolsExtension }

@NgModule({
  providerS: [DevToolsExtension]
})
export class AppModule {
  constructor(ngRedux:NgRedux<IAppState>, devTools:DevToolsExtension) {
    // config as before
  }
}
```

**IMPORTANT NOTE ABOUT AOT**

If using the ngc compiler and AoT compilation - `@select` decorators
will not work. If you want to use the ngc compiler (either directly, or
via angular-cli), and want to use the `@select` - you will need to use
the `--aot false` flag.

If you want to use AoT - the build process will work, but decorators
will silently stop working. If you want to use AoT.

**before**

```js
import { select } from 'ng2-redux';
export class MyComponent {
  @select() thing$:Observable<string>;
}
```

**after**

```js
import { NgRedux } from 'ng2-redux';
export class MyComponent {
  thing$:Observable<string>;
  constructor(private ngRedux:NgRedux<MyAppState>) {

  }
  ngOnInit() {
    this.thing$ = this.ngRedux.select (n => n.thing);
  }
}
```

We are big fans of how the `@select` works - and high priority to get
this working, but it seems to possibly be a limitation of the compiler.
Any feedback / help / suggestions to try and get this working with AoT
would be greatly appreciated.
@SethDavenport
Copy link
Member

@hasangilak regarding the NODE_ENV === "production" error - are you using angular-cli or webpack by any chance?

@SethDavenport
Copy link
Member

If you're using angular-cli I believe they've fixed this in beta-18. If you're using webpack, you'll need to use webpack.DefinePlugin to provide a value for process.env in the browser environment:

new webpack.DefinePlugin({
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
})

@SethDavenport
Copy link
Member

SethDavenport commented Oct 21, 2016

@dagstuan have you tried the latest ng2-redux 4.0.0 beta 7? I believe it resolves a number of AoT issues.

@SethDavenport
Copy link
Member

Closing for now. If you're still having AoT issues, be sure to reference #234 for the latest discussion.

@dagstuan
Copy link
Author

Hey, sorry about the late reply. I havent had issues with it lately as I've been waiting a while to try and implement it again :) But it looks like you guys have it under control. Thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants