2

Having error TS2304 during typescript build for all the references of module.id in all of my components definitions. Definition looks like this:

    @Component({
        selector: 'sd-app',
   =>   moduleId: module.id,
        templateUrl: './app.component.html',
        directives: [ROUTER_DIRECTIVES, NavbarComponent, FooterComponent],
        providers: [AuthService]
    })

Here is the error:

app\components\app.component.ts(15,15): error TS2304: Cannot find name 'module'.

Compilation completes and application works fine though.

Any idea how to get rid of this error?

5
  • It would help to give the code that the error is referencing. Commented Mar 30, 2016 at 21:22
  • 1
    Try declare var module: any? Commented Mar 30, 2016 at 21:26
  • Thanks, Is there a way to declare it globally, rather repeating in each component definition? Commented Mar 30, 2016 at 21:27
  • @Nexus23 that should work if you add that line in your main file (let's say bootstrap.ts), but I'm not 100% sure. Commented Mar 30, 2016 at 22:33
  • Possible duplicate of typescript getting error TS2304: cannot find name ' require' Commented Jan 7, 2017 at 16:23

1 Answer 1

3

error TS2304: Cannot find name 'module'

Because TypeScript cannot see the variable module declared anywhere.

Quickfix

Create a globals.d.ts with the following:

declare var module:any;
Sign up to request clarification or add additional context in comments.

1 Comment

Works like a charm. Thanks Basarat. I have put the globals.d.ts in my angular application root location which is the typescript files location for compilation as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.