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

@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 avatar Sep 17 '19 16:09 mohaxspb

@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 avatar Sep 17 '19 19:09 mohaxspb

@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

mohaxspb avatar Sep 18 '19 22:09 mohaxspb

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.