Matthew Layton
Matthew Layton

Reputation: 42229

How to solve the "module has no exported member" error?

I am following instructions from the this answer, but cannot make the solution work.

Overview

I want to use import { Type } from "Module" instead of /// <reference path="..." />

Structure

-app\
  -ViewModel.ts
  -Program.ts

ViewModel.ts

export module Demo {
    export class ViewModel {
        constructor(public test: string) {
        }
    }
}

Program.ts

import { ViewModel } from "ViewModel";

Module 'C:/DemoApp/app/ViewModel' has no exported member 'ViewModel'.

and...

Only 'amd' and 'system' modules are supported alongside --outFile.

Goal

I want to be able to reference dependencies so that they compile to a single file in order.


If I add "module": "system" I still get the 1st of the aforementioned errors.

As per the 1st solution, I do not want to lose namespaces.

Upvotes: 38

Views: 129838

Answers (3)

user19622927
user19622927

Reputation: 1

May not be or check the module which you're using there.

export a () => {
   console.log("Hello world!");
}

Upvotes: -2

AhuraMazda
AhuraMazda

Reputation: 470

One reason can be typo.

export const Demo = () => {} cannot be exported if it does not return a value.

export const Demo =()=> () can be exported without return.

Upvotes: 0

Ali Baig
Ali Baig

Reputation: 3867

Remove the line below from your statement

export module Demo

and use it like

export class ViewModel {
    constructor(public test: string) {
    }
}

Edit: For namespace, just do something like

namespace Demo {
  export class ViewModel {
        constructor(public test: string) {
        }
    }
}

Upvotes: 24

Related Questions