Function calls are not supported in decorators but 'NgForageModule' was called

Viewed 662

After upgrading to Angular 7 I am unable to create builds using AOT (using Ionic).

I run ionic cordova build android and get

ERROR in Error during template compile of 'AppModule'
  Function calls are not supported in decorators but 'NgForageModule' was called.

app.module.ts:

import {NgForageModule, Driver} from 'ngforage';

...

imports: [
    NgForageModule.forRoot({
      name: 'next-storage',
      driver: [
        Driver.INDEXED_DB,
        Driver.WEB_SQL,
        Driver.LOCAL_STORAGE
      ]
    }),
    ...
]
...
2 Answers

I had to use the DEFAULT_CONFIG provided and move my custom config from imports to providers.

Changes in app.module.ts:

import {Driver, NgForageOptions, DEFAULT_CONFIG} from 'ngforage';

...

const ngfRootOptions:NgForageOptions = {
  name: 'next-storage',
  driver: [
    Driver.INDEXED_DB,
    Driver.WEB_SQL,
    Driver.LOCAL_STORAGE
  ]
};

...

providers: [
    {
      provide:  DEFAULT_CONFIG,
      useValue: ngfRootOptions
    }
    ...
]
...

Author of Ngforage here.

This is a weird regression that was introduced in Angular 7. Nothing had changed in the library between ng6 and ng7, but, when I installed it using forRoot in ng7, I got the same error and using DEFAULT_CONFIG became the only config solution.

This was supposed to get fixed with Ivy, but it hadn't arrived in ng8; if it's still an issue in ng9, I'll remove the forRoot API altogether.

For reference:

Related