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

Angular6 - ng build / serve --prod - Error during template compile of 'AppModule' #368

Closed
kararade opened this issue Dec 11, 2018 · 19 comments

Comments

@kararade
Copy link

kararade commented Dec 11, 2018

I have this problem when I'm building or seving an Angular6 application for PROD with ng serve --prod or ng build --prod

ERROR in app/app.module.ts(84,47): Error during template compile of 'AppModule'
  Complex function calls are not supported. in 'intersectionObserverPreset'
    'intersectionObserverPreset' references 'intersectionObserverPreset'
      'intersectionObserverPreset' references 'intersectionObserverPreset'
        'intersectionObserverPreset' contains the error.

This is what I have in the line app/app.module.ts(84,47)

import { LazyLoadImageModule, intersectionObserverPreset } from 'ng-lazyload-image';
@NgModule({
    imports: [
             ...,
/*84 -->*/ LazyLoadImageModule.forRoot({ preset: intersectionObserverPreset }) /*<-- 84*/
    ],
    declarations:  [...],
    entryComponents [...],
    providers: [...],
    bootstrap: [...]
})

Versions:

angular: 6.1.0
ng-lazyload-image: 5.0.0
npm: 5.6.0
node: 8.11.4
typescript: 2.7.2

It seems to have something to do with AOT but I can't find a way to fix it. This error does not occur when normally running the commands ng build or ng serve

I appreciate any help

Thanks!

@kahnchen1028
Copy link

I have the same problem,plz help

@yah0130
Copy link

yah0130 commented Dec 28, 2018

in ionic4 angular7,build with --prod ,only show the default image,it is ok when build without --prod

@tjoskar
Copy link
Owner

tjoskar commented Jan 2, 2019

Is it working if you don't use intersectionObserverPreset?

imports: [
  LazyLoadImageModule
],

@kararade
Copy link
Author

kararade commented Jan 3, 2019

Hey @tjoskar

I had already tried to use the LazyLoadImageModule without the intersectionObserverPreset previously as you mention, but interestingly without it, the error is reproduced to me in all environments, dev and prod. To give you a little more context, these images are loaded inside a carousel-modal, I'm not sure if there's any conflict with that, but it doesn't seem.

Please, see below.

1. Setting up the module without the intersectionObserverPreset
imports: [
  LazyLoadImageModule
],
  • Doesn't work for the following commands: ng serve, ng serve --prod, ng build and ng build --prod

screen capture on 2019-01-03 at 10-08-27


2. Setting up the module including the intersectionObserverPreset
imports: [
    LazyLoadImageModule.forRoot({ preset: intersectionObserverPreset })
],
  • Doesn't work for the following commands: ng serve --prod and ng build --prod

It's giving me this error

ERROR in app/app.module.ts(84,47): Error during template compile of 'AppModule'
  Complex function calls are not supported. in 'intersectionObserverPreset'
    'intersectionObserverPreset' references 'intersectionObserverPreset'
      'intersectionObserverPreset' references 'intersectionObserverPreset'
        'intersectionObserverPreset' contains the error.
  • Works correctly for the following commands: ng serve and ng build

screen capture on 2019-01-03 at 10-15-33


Maybe it's something I'm not understanding well in relation to the use of intersectionObserverPreset. Any help will be appreciated.

Thank you!

@kahnchen1028
Copy link

kahnchen1028 commented Jan 4, 2019

Hello @tjoskar

ng-lazyload-img component loads image by scroll trigger what is a default behavior,
I got a the situation what the users don't need any scrolling to view carousel banner and
when the users click privious/next button in component,they will get an blank image,
so I need include intersectionObserverPreset to solve this issue,
but it can't work for ng serve, ng serve --prod, ng build and ng build --prod..

please help to fixed it
thank you :)

@tjoskar tjoskar added the bug label Jan 4, 2019
@tjoskar
Copy link
Owner

tjoskar commented Jan 8, 2019

Hi @kararade, if you don't use intersectionObserverPreset; ng-lazyload-image will trigger an image load on scroll but since you are using an image-carousel the user won't scroll and you need to trigger an event on "image-slide" (something like this: #197 (comment)) or using intersectionObserverPreset, which is the recommended way. However, as you notice, AOT won't work for some reason when using intersectionObserverPreset and I'm not sure why. I will try to take a look at it.

@tjoskar
Copy link
Owner

tjoskar commented Jan 8, 2019

@kahnchen1028, what version of Angular are you using?

@kararade, I created a Angular 7 app and installed ng-lazyload-image with intersectionObserverPreset and it seems to work fine with both ng serve --prod and ng build --prod. I can try to downgrade Angular to version 6 (which active license has ended for) but is there any chance that you will upgrade to version 7 any time soon?

@kararade
Copy link
Author

kararade commented Jan 8, 2019

@tjoskar let me check what happens upgrading to the version 7.
I will let you know!
Thanks

@johnqiuwan
Copy link

I have the exactly same issue, and I am using angular version 7.
It wokrs on 'ng serve' but not 'ng build --prod --aot'

is there any solution for the issue?

tjoskar added a commit to tjoskar/ng-lazyload-image-bugs that referenced this issue Feb 17, 2019
@tjoskar
Copy link
Owner

tjoskar commented Feb 17, 2019

@johnqiuwan, can you create a small repo where you reproduce the issue?
I just created this one and I can't reproduce it: https://github.com/tjoskar/ng-lazyload-image-bugs/tree/master/368-compile-error

I did the following:

$ ng new my-app
$ npm install ng-lazyload-image --save

Did the following code changes:
tjoskar/ng-lazyload-image-bugs@b0bb6e7

And run ng build --prod --aot

@tjoskar tjoskar removed the bug label Feb 17, 2019
@bryantlikes
Copy link

I created a pull request that recreates the issue. I was able to fix it in my project by moving the import with the forRoot out of the child module and into the main app module. Now it works fine for me and I don't see this issue anymore.

@tjoskar
Copy link
Owner

tjoskar commented Mar 6, 2019

@bryantlikes, I just tried it out and I don't get the error. For you that it doesn't work for; what version of angular-cli do you have? (ng --version)

@linjie997
Copy link

Angular CLI: 7.3.5
Node: 10.14.1
OS: win32 x64
Angular: 7.2.8

rxjs 6.4.0
typescript 3.2.4
webpack 4.28.4

@Gromov-Roman
Copy link

Gromov-Roman commented Mar 12, 2019

@tjoskar Good day, in my behavior i have no error, just some images not loaded in AOT compilation, same as not using intersectionObserverPreset. All images load after scrolling

LoadImageModule.forRoot({
    preset: intersectionObserverPreset
})
<img title="{{card.picture.title || card.title}}"
                 alt="{{card.picture.title || card.title}}"
                 class="lazy"
                 [defaultImage]="'assets/images/default-img.png'"
                 [lazyLoad]="card.picture.renders[emblem] | retina">

Angular CLI: 7.3.2
Angular: 7.2.4

Screenshot 2019-03-12 at 11 57 10

@Gromov-Roman
Copy link

@tjoskar Ou, updated to 5.1.1 and seemingly bug is gone)

@tjoskar
Copy link
Owner

tjoskar commented Mar 13, 2019

@Gromov-Roman, interesting.
@linjie997, is it possible for you to upgrade as well? (npm install ng-lazyload-image@5.1.1)

@linjie997
Copy link

Hi, I can confirm that updating solves the issue

@tjoskar
Copy link
Owner

tjoskar commented Apr 3, 2019

ng-lazyload-image@5.1.2 is now out. Let me know if the error still occur.

@tjoskar tjoskar closed this as completed Apr 3, 2019
@maxakash
Copy link

maxakash commented Apr 3, 2019

Updating to ng-lazyload-image@5.1.2 and angular 7 solved the issue. Thanks for resolving .

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

No branches or pull requests

9 participants