Alon
Alon

Reputation: 11885

TS2307: Cannot find module 'angular'

There are many questions on this exact error. Nevertheless, I cannot find one that fixes my problem. I'm probably missing something simple but I don't know what.

In my project I just created the first ts file - initialize.ts:

import angular from "angular";

namespace AngularTypeScriptStarterKit {
    angular
        .module('app', []);

}

Now the problem is that 'angular' is marked with red, saying:

TS2307: Cannot find module 'angular'

I have the declarations file for angular located at /typings/globals/angular/index.d.ts

Any help will be profoundly appreciated.

typings.json:

{
  "globalDependencies": {
    "angular": "registry:dt/angular#1.5.0+20160725073351",
    "jquery": "registry:dt/jquery#1.10.0+20170310222111"
  },
  "dependencies": {
    "angular": "registry:dt/angular#1.6.0+20170321201455"
  }
}

Please let me know for any other required information and I'll update my question.

Upvotes: 0

Views: 2096

Answers (2)

Suraj Rao
Suraj Rao

Reputation: 29614

Typings is deprecated.

You need to use DefinitelyTyped.

Just do :

npm install --save-dev @types/angular

index.d.ts reference

Upvotes: 2

Harrisss
Harrisss

Reputation: 363

If your application is not able to find module you should provide the typescript reference path on the first line of the file itself. Include following line of code : /// reference path="../../typings/index.d.ts" /, at top of Initialize.ts In typescript reference path is required for third party libraries so that typescript compiler can understand the method definitions. More on reference path in following link : https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

Upvotes: 3

Related Questions