flex-layout icon indicating copy to clipboard operation
flex-layout copied to clipboard

ES2015 support

Open S-Johny opened this issue 7 years ago • 44 comments

Bug Report

What is the expected behavior?

To make FlexLayoutServerModule work under firebase cloud function.

What is the current behavior?

Getting an error after successful deploy to a firebase.

What are the steps to reproduce?

  1. Create Angular repo with SSR
  2. Add FlexLayout
  3. Use firebase to deploy cloud function

functions/package.json

  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "main": "index.js",
  "dependencies": {
    "@angular/animations": "^7.1.0",
    "@angular/cdk": "^7.1.0",
    "@angular/common": "^7.1.0",
    "@angular/compiler": "^7.1.0",
    "@angular/core": "^7.1.0",
    "@angular/flex-layout": "^7.0.0-beta.22",
    "@angular/forms": "^7.1.0",
    "@angular/http": "^7.1.0",
    "@angular/platform-browser": "^7.1.0",
    "@angular/platform-browser-dynamic": "^7.1.0",
    "@angular/platform-server": "^7.1.0",
    "@angular/router": "^7.1.0",
    "@nguniversal/common": "^7.0.2",
    "@nguniversal/express-engine": "^7.0.2",
    "@nguniversal/module-map-ngfactory-loader": "^7.0.2",
    "@types/smoothscroll-polyfill": "^0.3.0",
    "firebase-admin": "^6.4.0",
    "firebase-functions": "^2.1.0",
    "compression": "^1.7.3",
    "core-js": "^2.5.4",
    "express": "^4.16.4",
    "hammerjs": "^2.0.8",
    "rxjs": "^6.3.3",
    "smoothscroll-polyfill": "^0.4.3",
    "ts-loader": "^5.3.0",
    "zone.js": "^0.8.26",
    "reflect-metadata": "^0.1.12"
  },
  "devDependencies": {
    "tslint": "^5.11.0",
    "typescript": "^3.1.6"
  },
  "private": true
}

app.server.module.ts

  imports: [
    AppModule,
    ServerModule,
    ModuleMapLoaderModule,
    ServerTransferStateModule,
    FlexLayoutServerModule,
  ],
  bootstrap: [AppComponent],
})
export class AppServerModule {}

error I am getting

TypeError: this.marshal.init is not a function
    at LayoutAlignDirective.BaseDirective2.init (/user_code/node_modules/@angular/flex-layout/bundles/flex-layout-core.umd.js:2416:22)
    at new LayoutAlignDirective (/user_code/node_modules/@angular/flex-layout/bundles/flex-layout-flex.umd.js:1529:15)
    at createClass (/user_code/node_modules/@angular/core/bundles/core.umd.js:20747:24)
    at createDirectiveInstance (/user_code/node_modules/@angular/core/bundles/core.umd.js:20616:24)
    at createViewNodes (/user_code/node_modules/@angular/core/bundles/core.umd.js:21842:40)
    at callViewAction (/user_code/node_modules/@angular/core/bundles/core.umd.js:22158:17)
    at execComponentViewsAction (/user_code/node_modules/@angular/core/bundles/core.umd.js:22077:17)
    at createViewNodes (/user_code/node_modules/@angular/core/bundles/core.umd.js:21870:9)
    at createRootView (/user_code/node_modules/@angular/core/bundles/core.umd.js:21756:9)
    at Object.createProdRootView [as createRootView] (/user_code/node_modules/@angular/core/bundles/core.umd.js:22268:16)
    at resolvePromise (/user_code/node_modules/zone.js/dist/zone-node.js:814:31)
    at resolvePromise (/user_code/node_modules/zone.js/dist/zone-node.js:771:17)
    at /user_code/node_modules/zone.js/dist/zone-node.js:873:17
    at ZoneDelegate.invokeTask (/user_code/node_modules/zone.js/dist/zone-node.js:421:31)
    at Object.onInvokeTask (/user_code/node_modules/@angular/core/bundles/core.umd.js:16192:37)
    at ZoneDelegate.invokeTask (/user_code/node_modules/zone.js/dist/zone-node.js:420:36)
    at Zone.runTask (/user_code/node_modules/zone.js/dist/zone-node.js:188:47)
    at drainMicroTaskQueue (/user_code/node_modules/zone.js/dist/zone-node.js:595:35)
    at ZoneTask.invokeTask (/user_code/node_modules/zone.js/dist/zone-node.js:500:21)
    at ZoneTask.invoke (/user_code/node_modules/zone.js/dist/zone-node.js:485:48)
  rejection: 
   TypeError: this.marshal.init is not a function
       at LayoutAlignDirective.BaseDirective2.init (/user_code/node_modules/@angular/flex-layout/bundles/flex-layout-core.umd.js:2416:22)
       at new LayoutAlignDirective (/user_code/node_modules/@angular/flex-layout/bundles/flex-layout-flex.umd.js:1529:15)
       at createClass (/user_code/node_modules/@angular/core/bundles/core.umd.js:20747:24)
       at createDirectiveInstance (/user_code/node_modules/@angular/core/bundles/core.umd.js:20616:24)
       at createViewNodes (/user_code/node_modules/@angular/core/bundles/core.umd.js:21842:40)
       at callViewAction (/user_code/node_modules/@angular/core/bundles/core.umd.js:22158:17)
       at execComponentViewsAction (/user_code/node_modules/@angular/core/bundles/core.umd.js:22077:17)
       at createViewNodes (/user_code/node_modules/@angular/core/bundles/core.umd.js:21870:9)
       at createRootView (/user_code/node_modules/@angular/core/bundles/core.umd.js:21756:9)
       at Object.createProdRootView [as createRootView] (/user_code/node_modules/@angular/core/bundles/core.umd.js:22268:16),
  promise: 
   ZoneAwarePromise {
     __zone_symbol__state: 0,
     __zone_symbol__value: 
      TypeError: this.marshal.init is not a function
          at LayoutAlignDirective.BaseDirective2.init (/user_code/node_modules/@angular/flex-layout/bundles/flex-layout-core.umd.js:2416:22)
          at new LayoutAlignDirective (/user_code/node_modules/@angular/flex-layout/bundles/flex-layout-flex.umd.js:1529:15)
          at createClass (/user_code/node_modules/@angular/core/bundles/core.umd.js:20747:24)
          at createDirectiveInstance (/user_code/node_modules/@angular/core/bundles/core.umd.js:20616:24)
          at createViewNodes (/user_code/node_modules/@angular/core/bundles/core.umd.js:21842:40)
          at callViewAction (/user_code/node_modules/@angular/core/bundles/core.umd.js:22158:17)
          at execComponentViewsAction (/user_code/node_modules/@angular/core/bundles/core.umd.js:22077:17)
          at createViewNodes (/user_code/node_modules/@angular/core/bundles/core.umd.js:21870:9)
          at createRootView (/user_code/node_modules/@angular/core/bundles/core.umd.js:21756:9)
          at Object.createProdRootView [as createRootView] (/user_code/node_modules/@angular/core/bundles/core.umd.js:22268:16) },
  zone: 
   Zone {
     _properties: { isAngularZone: true },
     _parent: 
      Zone {
        _properties: {},
        _parent: null,
        _name: '<root>',
        _zoneDelegate: [Object] },
     _name: 'angular',
     _zoneDelegate: 
      ZoneDelegate {
        _taskCounts: [Object],
        zone: [Circular],
        _parentDelegate: [Object],
        _forkZS: null,
        _forkDlgt: null,
        _forkCurrZone: [Object],
        _interceptZS: null,
        _interceptDlgt: null,
        _interceptCurrZone: [Object],
        _invokeZS: [Object],
        _invokeDlgt: [Object],
        _invokeCurrZone: [Circular],
        _handl

S-Johny avatar Dec 21 '18 13:12 S-Johny

Same here, does not work when with ivy.

es2015:

core.js:9110 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'init' of undefined
TypeError: Cannot read property 'init' of undefined
    at DefaultLayoutDirective.init (core.js:463)
    at new LayoutDirective (flex.js:176)
    at new DefaultLayoutDirective (flex.js:188)
    at core.js:9075
    at NodeInjectorFactory.DefaultLayoutDirective_Factory [as factory] (flex.js:192)
    at getNodeInjectable (core.js:8939)
    at instantiateAllDirectives (core.js:15215)
    at createDirectivesAndLocals (core.js:14611)
    at ɵɵelementStart (core.js:19505)
    at PresentationLayoutComponent_Template (template.html:18)
    at resolvePromise (zone-evergreen.js:797)
    at resolvePromise (zone-evergreen.js:754)
    at zone-evergreen.js:858
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:34184)
    at ZoneDelegate.invokeTask (zone-evergreen.js:390)
    at Zone.runTask (zone-evergreen.js:168)
    at drainMicroTaskQueue (zone-evergreen.js:559)
    at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:469)
    at invokeTask (zone-evergreen.js:1603)

es5:

core.js:7376 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'init' of undefined
TypeError: Cannot read property 'init' of undefined
   at DefaultLayoutDirective.push../node_modules/@angular/flex-layout/__ivy_ngcc__/esm5/core.es5.js.BaseDirective2.init (core.es5.js:539)
   at DefaultLayoutDirective.LayoutDirective [as constructor] (flex.es5.js:178)
   at new DefaultLayoutDirective (flex.es5.js:193)
   at core.js:7351
   at NodeInjectorFactory.DefaultLayoutDirective_Factory [as factory] (flex.es5.js:197)
   at getNodeInjectable (core.js:7254)
   at instantiateAllDirectives (core.js:12015)
   at createDirectivesAndLocals (core.js:11540)
   at ɵɵelementStart (core.js:15419)
   at PresentationLayoutComponent_Template (template.html:18)
   at resolvePromise (zone.js:852)
   at resolvePromise (zone.js:809)
   at zone.js:913

Enngage avatar Jul 01 '19 07:07 Enngage

All: this is an issue with Angular or the Angular CLI (my thought it the latter). Please direct all requests to those repositories, but feel free to link back to this issue.

Keep in mind, this was never actually a Flex Layout issue, we just needed to wait for the requisite changes in the Angular compiler before we closed it since so many people encountered it with this library.

CaerusKaru avatar Jul 01 '19 17:07 CaerusKaru

Does anyone know if there is an open issue at the angular repo? Or some other place to see how this is evolving? Thanks

mfreirehfexp avatar Jul 10 '19 13:07 mfreirehfexp

@mfreirehfexp iirc there is an issue on the main angular repo. It's basically just waiting for ivy to release fully since it will fix this and the es2015 related compilation issues(ivy supports es2015). Sorry can't find the link but follow general ivy developments.

epelc avatar Jul 10 '19 14:07 epelc

@mfreirehfexp could you post link if you find it?

@epelc thanks for the reply, it is my understanding ivy wont be released until Angular 9, so are you saying this will not be fixed until then?

spencerfontein avatar Jul 10 '19 14:07 spencerfontein

@spencerfontein Yeah, from my understanding we are waiting until angular 9 at least now(hopefully it's fully released for 9). You are pretty much SOL until then(forced to compile to different target) since ivy is still so early now(I've tried you just keep running into other bugs and isn't worth attempting yet).

epelc avatar Jul 10 '19 14:07 epelc

Thanks @epelc ! I have a couple of months so I guess I'll wait

mfreirehfexp avatar Jul 10 '19 14:07 mfreirehfexp

For those wondering, I changed all of my angular packages to be 8.2.0, or higher. Still not able to use flex-layout @CaerusKaru

CharGrnmn avatar Aug 05 '19 16:08 CharGrnmn

I'm also seeing this with CLI 8.2.0 with ivy enabled and target es2015 (flex-layout 8.0.0-beta.26).

james-schwartzkopf avatar Aug 06 '19 15:08 james-schwartzkopf

I'm having this error in CLI 8.2.3 with ivy enabled, flex-layout 8.0.0-beta.26. Switch off ivy could get my app run without error. But it would be nice to have ivy.

nnworkspace avatar Aug 10 '19 09:08 nnworkspace

@Enngage that issue was reported to angular/angular in https://github.com/angular/angular/issues/32289. However, it looks like it was mistakenly marked as a duplicate.

Splaktar avatar Aug 27 '19 21:08 Splaktar

There are some new updates related to Ivy in https://github.com/angular/angular/issues/31956.

Splaktar avatar Aug 29 '19 23:08 Splaktar

I ran into this issue, but without Ivy enabled. The fix/workaround for me was to set "aot": true; along with "optimization": true and I kept the tsconfig target to ES2015.

drc-nloftsgard avatar Sep 04 '19 21:09 drc-nloftsgard

In relation to Ivy, this should be fixed in v8.0.0-beta.27.

Splaktar avatar Sep 06 '19 23:09 Splaktar

I was running into this error message without having opted into Ivy.

My build command has --aot=false and --buildOptimizer=false. Also adding --optimization=false seems to have fixed the issue for me.

plurch avatar Sep 13 '19 17:09 plurch

@plurch thanks! I add --optimization=false and it really helps.

mohaxspb avatar Sep 14 '19 22:09 mohaxspb

You certainly want to avoid deploying to production if you have --buildOptimizer=false --optimization=false in your build config, unless it's an internal only app that is only used via the internal company network...

Splaktar avatar Sep 16 '19 01:09 Splaktar

@Splaktar

You certainly want to avoid deploying to production if you have --buildOptimizer=false --optimization=false in your build config, unless it's an internal only app that is only used via the internal company network...

Could you provide more details? Do you mean performance issues or there are some security problems? For now I, seems to be, have no choice... I have empty error message with --aot=false and --buildOptimizer=false, so can't imaging what I need to fix. And with this options my app builds, but fails on load in browser, and only --optimization=false helps here. And I also can't use ng update --all, as there are dependencies issues.

May be I'll try to update each dep manually, but is it worth it? I'm not sure, that this will help...

mohaxspb avatar Sep 16 '19 12:09 mohaxspb

@mohaxspb Performance is the primary concern. Both runtime and load time.

You really should try to get your app building and working with AOT, otherwise it's not production ready.

You can run ng update --all --force, but there are some bugs currently that may update your dependencies for a -next.x release. If that occurs, you can manually downgrade the libraries to the latest 8.2.x release. The migrations that are applied should still work with that version.

Personally, I like to do ng update @angular/cli --force first, then run ng update again to see if anything else needs to be updated. Then I also use npm-check -u (here) to update any other non-ng-update dependencies that aren't breaking. Of course, if something breaks, then you will need to revert to the old version of that library (hopefully for only 1 or 2 dependencies).

If you run into problems, please feel free to create a StackOverflow question and then ping me on Gitter/Twitter and I can try to take a look.

Splaktar avatar Sep 16 '19 17:09 Splaktar

@Splaktar thanks for details! I'll try to update deps this week and write here about result)

mohaxspb avatar Sep 16 '19 18:09 mohaxspb