born2net
born2net

Reputation: 24993

TypeScript and ng2 rc.1 getting Error:(20, 15) TS2304: Cannot find name 'module'

TypeScript and ng2 rc.1 getting Error:(20, 15) TS2304: Cannot find name 'module'.

when trying to use directive of module as in

@Component({
    selector: 'Notes1',
    moduleId: module.id,
    directives: [ModalDialog, FORM_DIRECTIVES, DisplayError],
    templateUrl: 'Notes1.html',
    styleUrls: ['Notes1.css']
})

any idea how to fix the TS error.. all is working fine at runtime

regards

Sean

Upvotes: 2

Views: 2174

Answers (2)

JAM
JAM

Reputation: 21

The way I fixed this was to simply add Id after module like this "moduleId": "commonjs", in my tsconfig file and the error went away!

Hope this helps, Jim

Upvotes: -1

Shuhei Kagawa
Shuhei Kagawa

Reputation: 4777

The error means TypeScript compiler doesn't know what module is. For a quick fix:

declare var require: any;

To make it more complete, use a definition from DefinitelyTyped/node:

interface NodeRequireFunction {
    (id: string): any;
}

interface NodeRequire extends NodeRequireFunction {
    resolve(id:string): string;
    cache: any;
    extensions: any;
    main: any;
}

declare var require: NodeRequire;

interface NodeModule {
    exports: any;
    require: NodeRequireFunction;
    id: string;
    filename: string;
    loaded: boolean;
    parent: any;
    children: any[];
}

declare var module: NodeModule;

Upvotes: 2

Related Questions