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

ES2015 support #950

Closed
S-Johny opened this issue Dec 21, 2018 · 44 comments
Closed

ES2015 support #950

S-Johny opened this issue Dec 21, 2018 · 44 comments

Comments

@S-Johny
Copy link

S-Johny commented Dec 21, 2018

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 S-Johny changed the title Make flex-layout work on firebase cloug functions Make flex-layout work on firebase cloud functions Dec 21, 2018
@CaerusKaru
Copy link
Member

Can you post a minimal reproduction repository for this? SSR issues are tough to debug unless we have the while picture.

@S-Johny
Copy link
Author

S-Johny commented Dec 21, 2018

I am afraid that I can do that only after holidays. I can try to create a demo but my hopes are very low during the holidays sorry.

@epelc
Copy link
Contributor

epelc commented Dec 21, 2018

Didn't notice this was a duplicate at first. Thanks for pointing out @CaerusKaru hopefully I added some helpful info in the other issue.

Anyways @layyy you should be able to workaround for now if you can get the firebase project to target es5.

@CaerusKaru CaerusKaru changed the title Make flex-layout work on firebase cloud functions ES2015 support Dec 21, 2018
@CaerusKaru CaerusKaru added this to Pending in API Fixes via automation Dec 21, 2018
@CaerusKaru CaerusKaru self-assigned this Dec 21, 2018
@CaerusKaru
Copy link
Member

@epelc No worries, it was non-obvious. Thanks for identifying the root cause, I'll work with Paul to track this down.

@CaerusKaru
Copy link
Member

Marking this as blocked on angular/angular#27267. Workaround for now is as @epelc said, use ES5. Alternatively, you could reimplement the directives using explicit constructors, and declare those instead. We're opting not to in order to cut down on complexity and breaking changes for people using custom breakpoints.

@perjerz
Copy link

perjerz commented Dec 26, 2018

I have similar issue #959.
I solve the problem by downgrade version to beta.19 for now.

@CaerusKaru CaerusKaru removed this from Pending in API Fixes Dec 28, 2018
@CaerusKaru CaerusKaru removed this from the Backlog milestone Dec 31, 2018
@dima11221122
Copy link

In my project for flex-layout I use this workaround from material.

@CaerusKaru
Copy link
Member

@dima11221122 Be advised that Material reverted that change, see here. The workaround may still work for you if you don't use Closure Compiler, but for those who do beware.

@dima11221122
Copy link

At least for angular-cli projects it works properly:)

@epelc
Copy link
Contributor

epelc commented Jan 1, 2019

Angular cli projects default to es5. I’m actually using an angular cli project but wanted to target es2015 instead.

@sarora2073
Copy link

fyi - for me this issue occurs for using flex layout v7.0.0-beta.24 with angular 7.2.15 (i.e. not just an angular 8 issue as suggested above). I had rolled back a failed ng 8 upgrade, but my tsconfig was still targeting es2015, and that's when this flex layout issue cropped up for me. I changed my tsconfig.json's back to targeting es5 and the issue cleared up in my dev build (ng build --dev).

@spencerfontein
Copy link

spencerfontein commented Jun 18, 2019

Having same issue as @epelc

Using flex beta 26 and angular 8

And this is set in my prod build

"optimization": true, "outputHashing": "all", "sourceMap": true, "extractCss": true, "namedChunks": false, "aot": false, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": false, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" }

Only solution I have found is to set "optimization": false, and then it will run but then that isnt really ideal. Is there any update on a resolution for this?

Update:

I set target to es5 in the tsconfig.json and build worked, but es2015 does not

@spencerfontein
Copy link

@CaerusKaru can we get this reopened?

@Enngage
Copy link

Enngage commented Jul 1, 2019

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

@CaerusKaru
Copy link
Member

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.

@mfreirehfexp
Copy link

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

@epelc
Copy link
Contributor

epelc commented Jul 10, 2019

@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.

@spencerfontein
Copy link

@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?

@epelc
Copy link
Contributor

epelc commented Jul 10, 2019

@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).

@mfreirehfexp
Copy link

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

@CharlieGreenman
Copy link

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

@james-schwartzkopf
Copy link

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

@nnworkspace
Copy link

nnworkspace commented Aug 10, 2019

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.

@Splaktar
Copy link
Member

@Enngage that issue was reported to angular/angular in angular/angular#32289. However, it looks like it was mistakenly marked as a duplicate.

@Splaktar
Copy link
Member

There are some new updates related to Ivy in angular/angular#31956.

@drc-nloftsgard
Copy link

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.

@Splaktar
Copy link
Member

Splaktar commented Sep 6, 2019

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

@plurch
Copy link

plurch commented Sep 13, 2019

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.

@mohaxspb
Copy link

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

@Splaktar
Copy link
Member

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...

@mohaxspb
Copy link

mohaxspb commented Sep 16, 2019

@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...

@Splaktar
Copy link
Member

@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.

@mohaxspb
Copy link

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

@mohaxspb
Copy link

@Splaktar hello again!

I tried to update, but it doesn't help. While updating with ng update --all --force I have to decrease manually only zone.js and typescript.

So there is a question on stackoverflow:
https://stackoverflow.com/questions/57978475/angular-prod-build-error-in-cannot-assign-to-a-reference-or-variable

It would be great if you find time to take a look at it!

Anyway, thanks for helping, at least I managed deps updating)

@mohaxspb
Copy link

mohaxspb commented Sep 17, 2019

@Splaktar , at last I have error reason (SO user https://stackoverflow.com/users/10123947/shadow found it): there were attempt to change value of variable in template, defined in template with help of self-made directive.

Problem here is in poor error message. Mentioned user received details only via debugging compiler (as I understand). There are some details https://stackoverflow.com/a/57981144/3212712. Same in Russian: https://ru.stackoverflow.com/a/1025417/17609

To get error message I have to edit node_modules/@angular/compiler/bundles/compiler.umd.js, adding console.log(ast); before error throwing here (class _AstToIrVisitor, method visitPropertyWrite):

console.log(ast);
// Otherwise it's an error.
throw new Error('Cannot assign to a reference or variable!');

So I get this message:

PropertyWrite {
  span: ParseSpan { start: 0, end: 73 },
  receiver: ImplicitReceiver { span: ParseSpan { start: 0, end: 0 } },
  name: 'translation',
  value: MethodCall {
    span: ParseSpan { start: 14, end: 73 },
    receiver: ImplicitReceiver { span: [ParseSpan] },
    name: 'getTranslationForLanguageFromArticle',
    args: [ [PropertyRead], [PropertyRead] ]
  }
}

With this info I can immediately find problem in code.

UPD:

I found a way to use my directive and do not ruin prod build. But this needs to edit compiler script here

There is check for type of expression in template if (localExpr instanceof ReadPropExpr) and, if add one more condition || localExpr instanceof ReadVarExpr) everything is OK (prod build succeeded, so as deploy and run in browser). I'll try tomorrow to create pull request to compiler with example. Also there is a way to provide more info in error by adding JSON.stringify(ast) to error message.

@mohaxspb
Copy link

mohaxspb commented Sep 18, 2019

@Splaktar, hello again!

I add issues and PRs to angular repository to fix it.

  1. No details in error message: issue, PR
  2. Assigning value to template variable crashes prod build: issue, PR

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests