Cannot find name 'exports' error in typescript

Viewed 8626

I have a typescript file like below,

Environment.ts

var Environment = "DEV"
exports.Environment = Environment;

And I am using it in my app.config file like below,

var execEnv = require('./src/execEnvironment.ts');

which gives me the error

cannot find name 'exports'.

What am I doing wrong?

3 Answers

Use "standarized" ES6 style exports which are supported by Typescript

environment.ts

export const Environment = "DEV"

app.config.ts

import {Environment} from './environment'  // <= no .ts at the end

You can even rename on import

import {Environment as execEnv} from './environment'

try like this :

environment.ts file

export const environment = {
    production: false
};

app.config.ts

var execEnv = require('./src/execEnvironment.ts');

Use export var Environment = 'DEV';

instead of var Environment = "DEV" exports.Environment = Environment;

Related