Angular: Import of json file directly not working in production build

Viewed 332

I have to import a json file directly which works fine with ng serve but produces following error while ng build --prod

ERROR in Cannot read property 'Symbol(Symbol.iterator)' of undefined

Here is what my code looks like:

app.module.ts:

import * as cfgData from '../assets/config/config.json';

...

export function getWhiteList() {
  let x = (<any>cfgData).apiServer.whiteListDomains;
  return x;
}

  imports: [
     ...
     JwtModule.forRoot({
       config: {
        tokenGetter: tokenGetter,
        whitelistedDomains:getWhiteList()
       }
    })
  ],
  ...

Then I created a file called typings.d.ts with following content:

declare module "*.json" {
    const value: any;
    export default value;
}

where I get the error message that value was allready declared.

in tsconfig.json in compilerOptions added:

"compilerOptions": {
    "resolveJsonModule": true,
    ...
    "types": [
          "node"
       ],
        "typeRoots": [
          "node_modules/@types",
          "src/typings.d.ts"
        ],
    ...
  }

and in tsconfig.spec.json I added typings.d.ts to files:

"files": [
    "test.ts",
    "polyfills.ts",
    "typings.d.ts"
  ],

I am trying to solve this since two days. Angular is the most frustrating language I have ever worked with.

Does someone has any ideas?

================================

I don't know what I have done but it does not work with regular ng serve too by now.

0 Answers
Related