angular-redux / store

Angular 2+ bindings for Redux
MIT License
1.34k stars 202 forks source link

Unexpected value 'NgReduxModule' imported by the module 'AppEngine' #228

Closed NeoLSN closed 7 years ago

NeoLSN commented 7 years ago
ngc error: Error: Unexpected value 'NgReduxModule' imported by the module 'AppEngine'

Did someone know how to solve it?

dagstuan commented 7 years ago

Its due to missing metadata.json-files, see #223.

e-schultz commented 7 years ago

I hope to get this fixed this week, just been travelling and haven't had time to fully test things, but having ng2-redux work with AoT is high on my priority list.

e-schultz commented 7 years ago

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 commented 7 years ago

Some update/progress:

Working on a repo with master of angular-cli.

https://github.com/e-schultz/ng2-redux-aot-example/pull/1

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

NeoLSN commented 7 years ago

@e-schultz still the same problem.

h2qutc commented 7 years ago

Hi, Is there a tuto or a book that explain how to create a file metadata.json for a file *.d.ts ? Thanks

dagstuan commented 7 years ago

@h2qutc ngc automatically generates them when it builds a project, there is nothing else to it :) If the project is built with ngc it will have *.metadata.json files along with .js files.

smkamranqadri commented 7 years ago

any expected date when it will be resole, i stuck with ionic 2 rc0 app. which is using ngc and giving below error.

ngc: Error: Unexpected value 'NgReduxModule' imported by the module 'StoreModule'

duydao commented 7 years ago

Could this issue be related to the fact that NgRedux is using generic types?

https://github.com/angular/angular/issues/11057

h2qutc commented 7 years ago

Hi, I managed to resolve this error. I create a new module to remplace NgReduxModule and add it into imports

import { NgModule } from '@angular/core'; import { NgRedux, select } from 'ng2-redux';

@NgModule({ imports: [ ], declarations: [ ], exports: [ ], entryComponents: [ ] }) export class AppNgReduxModule { static forRoot() { return { ngModule: AppNgReduxModule, providers: [NgRedux], }; } }

Although I'm having another error and I not sure that this is a workaround for this issus. Anyway, I don't have this error anymore. But now, I got an another error:

ngc: Error: Error at c:/MCNEXT/Vinci/Vinci-RSC%20Mobile/.tmp/app/app.module.ngfactory.ts:174:15: Generic type 'NgRedux<RootState>' requires 1 type argument(s).

Any help please?

SethDavenport commented 7 years ago

seems likely that it is due to the issue referenced by @duydao. NgRedux has a type parameter so you can strongly type your store; it would be a shame to sacrifice this. The increasing list of basic language constructs not supported by AoT is becoming tiresome.

Nonetheless we'll see what we can do. @e-schultz let's chat more about this when you're back.

smkamranqadri commented 7 years ago

i wan thinking to switch to ngrx/store instead as i can't wait for the issue to be resolve.

smkamranqadri commented 7 years ago

i got solution to complete the app with ngc and no need to switch. well looking forward for the resolution as soon as possible.

NeoLSN commented 7 years ago

@e-schultz @SethDavenport Just hope this issue can be resolved as soon as you can.

h2qutc commented 7 years ago

@smkamranqadri Can you share the solution that you got please?

smkamranqadri commented 7 years ago

find can find here...

https://github.com/driftyco/ionic-cli/issues/1504

e-schultz commented 7 years ago

My update on this:

I have a version working npm install ng2-redux@aot-beta that will have things working with AoT compiling and not complain about

Unexpected value 'NgReduxModule' imported by the module 'AppEngine'

However, @select decorators do not work - and I'm trying to find a way to resolve this.

I was hoping to have both issues resolved in one release, as well - I'm big fan of @select

Another workaround is to do a prod build, but with AoT turned off

ng build --aot false -prod

If people are ok with @select not working and changing their code from

class MyClass {
 @select() stuff$;
}

// to

class MyClass {
    stuff$;

  ngOnInt() { 
   this.stuff=this.ngRedux.select('stuff');
  }
}

I can push out a non beta release of this soon.

I have an idea later tonight I want to try out to get @select working, but would possibly mean needing to inject ngRedux into your components/services even if you were not using it as everything else is being done from the decorators.

e-schultz commented 7 years ago

note: when I say @select doesn't work - the app compiles, but when you view the pages/views generated - they do not work as expected.

NeoLSN commented 7 years ago

@e-schultz If there is a ng2-redux@aot-beta, I can do with this first. Thanks.

But it is still got error ngc: Error: Error at ... Generic type 'NgRedux<RootState>' requires 1 type argument(s).

h2qutc commented 7 years ago

+1

NeoLSN commented 7 years ago

I tried that using "--dev" to build app. And, yes, the app can be built, but when app open it always shows Uncaught ReferenceError: module is not defined. If I choose to build app without adding "--dev" , I always get message - ngc: Error: Error at ... Generic type 'NgRedux<RootState>' requires 1 type argument(s). My current ng2-redux version is "ng2-redux": "^4.0.1-beta.3"

Could someone give me any suggestion?

duydao commented 7 years ago

@NeoLSN I run into the same error message, but it was caused by a dependency of redux itself (symbol-observable@1.0.3).

There seems to be a difference of the index.js file on git (https://github.com/blesh/symbol-observable/blob/master/es/index.js) and the npm package.

I've already created an issue for it: https://github.com/blesh/symbol-observable/issues/26

for now, you could replace the content of the index.js file in your node_modules with the one on git: (https://github.com/blesh/symbol-observable/blob/master/es/index.js)

duydao commented 7 years ago

@e-schultz Could you share your current progress on this issue? Maybee we are able to help figuring out why the select doesn't work

h2qutc commented 7 years ago

For someone who want to build with JIT compiler https://forum.ionicframework.com/t/ionic-build-android-with-jit-compiler/66564

NeoLSN commented 7 years ago

@e-schultz Will this ngc: Error: Error at ... Generic type 'NgRedux<RootState>' requires 1 type argument(s). also fix in this issue?

e-schultz commented 7 years ago

@NeoLSN can you try ng-redux@aot-beta? I'm not getting that issue in the toy app that I'm playing around with.

The issue seems to be that AoT just doesn't like decorators that mutate the class. Even creating a simple decorator that adds a getter to return the string 'this works' - works without AoT, stops working with AoT - no error/bug/warning, just silently stops working.

The 'list of things that AoT doesn't support / throws errors on / silently has failing behavior with no error or warning' has me questioning the readiness of AoT for production use (even outside of use with ng2-redux).

Later tonight I'll push up my work in progress / example app.

Ideally I wanted to get a release out that would have both the module issue + decorators working in the same release, but what I may need to do is a release w/o decorators working with migration docs (pretty easy, but annoying - and really want to avoid pushing that onto the users), and then try and see if I can figure out a solution for the decorators.

NeoLSN commented 7 years ago

@e-schultz Yes, I'm using ng2-redux@aot-beta. image And when I call npm run build, I'll get image I work with @duydao 's suggestion now, but it seems a workaround that building code without ngc. If I want to build code with ngc, do you have any suggestion?

spock123 commented 7 years ago

Thank you for all the great work, guys.. I'd seriously be sad to lose @select, it's so elegant and brilliant....

e-schultz commented 7 years ago

There seems to be challenges with the ngc compiler working with generics as injectables and there is an issue on the angular repo for it,

But when that issue gets closed with "its by design", and "I'm making a list of patterns that are supported and not by AoT - but it's taking too long because the only way to see the error is to run it" is what makes me go 😱 and question AoT's readiness for production.

I've been playing around with the angular cli, and also compiler cli - is if you don't tell ngc to ignore .ngfactory files - first run things work, generates the .ngfactory files, then next time you run it - it tries to run ngc on the generated factory files, then chokes on those.

WIth the cli-generated project I've been playing with, if I try and use ngc directly

screen shot 2016-10-13 at 10 13 22 pm

If you tweak your config to tell it to put the angular compiler generated files elsewhere ...

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
   "angularCompilerOptions": {
    "genDir": "../ngfactory"
  }
}

so that ngc won't try to recompile it's own output - the error from compiling stops happening. I haven't tried to actually bootstrap/run the output yet - so unsure if it works as expected, but at least the compiler stops complaining.

Not sure how much of a help this is, just sharing the findings from my exploration so far.

NeoLSN commented 7 years ago

Thanks for your exploration, @e-schultz.

Current I just use hasangilak mentioned solution on #223 to avoid that error.

danielcrk-cn commented 7 years ago

@NeoLSN I can't get the solution to work, I create a wrapper according to the instructions, import it into app.module.ts and add it to the providers array, but when the application starts, i get the "No provider for NgRedux!" error. If I provide NgRedux directly, everything but the AoT works.

Would you mind providing a bit more info about the workaround? Thanks!

NeoLSN commented 7 years ago

@danielcrk-cn You should do provide your wrapper service like providers: [..., NgReduxWrapper] and use it contructor(..., private ngReduxWrapper: NgReduxWrapper) { }

danielcrk-cn commented 7 years ago

@NeoLSN Aaaah, ofc, it should be referenced as NgReduxWrapper in every component as well. I think this should be quite easily done with a "search and replace", i hope =p

Thanks!

e-schultz commented 7 years ago

Just published a new beta.

Slight change with how you import the module, now should do NgReduxModule.forRoot,

change-log details

NeoLSN commented 7 years ago
[23:48:57]  Error: Error encountered resolving symbol values statically. Function calls are not supported.
            Consider replacing the function or lambda with a reference to an exported function, resolving
            symbol AppModule in .../app.module.ts,
            resolving symbol AppModule in .../app.module.ts
[23:48:57]  ngc failed
[23:48:57]  ionic-app-script task: "build"
[23:48:57]  Error: Error

Did I do something wrong?

NeoLSN commented 7 years ago

Just provide another workaround.

  1. Directly extends NgRedux.
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';

@Injectable()
export class _NgRedux extends NgRedux<any> {

    constructor() {
        super();
    }
}
  1. In app module, do things like below
import { NgRedux } from 'ng2-redux';
import { _NgRedux } from './_ng-redux';

@NgModule({
    ...,
    providers: [
        ...,
        { provide: NgRedux, useClass: _NgRedux },
    ]
})
export class MyApp {

    constructor(
        ...,
        private ngRedux: NgRedux<any>
    ) {}
}

This method will be better than using wrapper class. If you want to use ng2-redux-router or other library which based on ng2-redux.

It is still a workaround. Don't do this if you have another choice.

danielcrk-cn commented 7 years ago

@NeoLSN Thanks for posting this man! Will give it a go!

e-schultz commented 7 years ago

@danielcrk-cn @NeoLSN 4.0.0-beta.7 is now out, should fix that issue now - I had broken the generation of the metadata file which should be resolved now.

danielcrk-cn commented 7 years ago

I've tried the new beta now, and still get the same error, Generic type 'NgRedux<RootState>' requires 1 type argument(s)

In app.module.ts, i've added NgReduxModule.forRoot() to the imports array. Should this still be the correct way to do it?

danielcrk-cn commented 7 years ago

@NeoLSN your latest workaround seems to be working great! thanks again!

SethDavenport commented 7 years ago

@danielcrk-cn I have been able to get ng2-redux@4.0.0-beta.7 working with Angular CLI and AoT here: https://github.com/SethDavenport/ng2-redux--with-aot

To run it, clone the repo and do:

npm install -g angular-cli@1.0.0-beta.18
npm install
ng serve # serve without AoT - works fine
ng serve --aot # serve with AoT - also works fine

Can you share your repo where you're having the issue?

SethDavenport commented 7 years ago

@NeoLSN, @danielcrk-cn: it's unfortunate that we have to resort to such a workaround. I myself am having trouble reproducing the 'generic' error, but some of my colleagues have encountered it; my working theory is that it happens when you use ngc but not when you use the --aot mode of angular-cli.

Further, I suspect that we may be able to resolve it by dropping the @Injectable decorator from the NgRedux class. It's redundant anyway because of the manual provider we construct in NgReduxModule.forRoot().

I've published a tag to test this out; can you try npm install --save ng2-redux@aotfun and let me know if you still get the 'generic' error?

SethDavenport commented 7 years ago

Fixed in 4.0.0.

MichalZak commented 7 years ago

I just upgraded to 4.0.0, but im still getting the error. Generic type 'NgRedux' requires 1 type argument(s).

Besides using NgReduxModule.forRoot(), what else do I need to make sure of. Im developing with Ionic2/Webpack

Mike

NeoLSN commented 7 years ago

@SethDavenport Yes, I still get Generic type 'NgRedux' requires 1 type argument(s). issue.

Sorry for the late response.

SethDavenport commented 7 years ago

can you try an rm -rf node_modules; npm cache clean; npm install ?

NeoLSN commented 7 years ago

@SethDavenport

[09:44:06]  Error: Error at <project_root>/.tmp/app/app.module.ngfactory.ts:129:15
[09:44:06]  Generic type 'NgRedux<RootState>' requires 1 type argument(s).
[09:44:06]  ngc failed
[09:44:06]  ionic-app-script task: "build"
[09:44:06]  Error: Error
SethDavenport commented 7 years ago

I believe I have identified the cause. Working on a fix now.

SethDavenport commented 7 years ago

FWIW, if you're struggling with AoT in any of your own code, my colleague @watrool has build a very handy test harness for AoT issues: https://github.com/rangle/angular-2-aot-sandbox

SethDavenport commented 7 years ago

Can you try ng2-redux@4.1.0? Should be fixed now. Sorry about that.