Friday, 1 November 2019

exports is not defined error in angular 8

I have created a JSON config that has been added to my angular 8 project. Ever since I have made changes in the way the config is imported in the project, I get error when trying to serve the project in prod mode. I am getting error exports is not defined. Not sure why it complains in prod mode and runs fine in dev mode.

Error

enter image description here

Following is my code changes

If you notice I have added the following two lines of code in tsconfig

"resolveJsonModule": true,
 "esModuleInterop": true

tsconfig.json

{
  "compileOnSave": true,
    "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "allowJs": true,
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom"
        ],
        "module": "UMD",
        "resolveJsonModule": true,
        "esModuleInterop": true
    } 
}

config.json

{
    "settings": {
        "production": false,
        "userIdleMinutes": "10",
        "corePingIntervalSeconds": "10",
        "baseUrl": "http://localhost:57973",
        "loginUrl": "/Login",
        "adminUrl": "/Admin"
    }
}

This is the way it has been imported in the enviornment.ts

enviornment.ts

import config from '../assets/config.json'

// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
    production: config.settings.production,
    baseUrl: config.settings.baseUrl,
    loginUrl:config.settings.loginUrl,
    adminUrl: config.settings.adminUrl,
    userIdleMinutes: config.settings.userIdleMinutes,
    corePingIntervalSeconds: config.settings.corePingIntervalSeconds 
};


from exports is not defined error in angular 8

No comments:

Post a Comment