【问题标题】:TS2307: Cannot find module 'angular'TS2307:找不到模块“角度”
【发布时间】:2017-10-13 07:13:44
【问题描述】:

关于这个确切的错误有很多问题。不过,我找不到一个可以解决我的问题的。我可能遗漏了一些简单的东西,但我不知道是什么。

在我的项目中,我刚刚创建了第一个 ts 文件 - initialize.ts:

import angular from "angular";

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

}

现在的问题是'angular'被标记为红色,表示:

TS2307:找不到模块“角度”

我的 Angular 声明文件位于 /typings/globals/angular/index.d.ts

任何帮助将不胜感激。

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"
  }
}

请让我知道任何其他必需的信息,我会更新我的问题。

【问题讨论】:

  • 有什么原因没有切换到@types?不推荐使用类型
  • @suraj 我刚刚切换到类型,它解决了我的问题。请将此重写为答案,我会接受。
  • 很高兴它起作用了 :) .. 添加了答案

标签: javascript angularjs node.js typescript typescript-typings


【解决方案1】:

如果您的应用程序无法找到模块,您应该在文件本身的第一行提供 typescript 引用路径。包括以下代码行: /// 参考路径="../../typings/index.d.ts" /, 在 Initialize.ts 的顶部,第三方库需要在 typescript 中引用路径,以便 typescript 编译器可以理解方法定义。更多关于以下链接的参考路径:https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

【讨论】:

    【解决方案2】:

    不推荐使用类型。

    您需要使用DefinitelyTyped

    只要做:

    npm install --save-dev @types/angular
    

    index.d.ts reference

    【讨论】:

      猜你喜欢
      • 2017-03-18
      • 2017-03-09
      • 2022-11-02
      • 2019-11-29
      • 2017-09-27
      • 1970-01-01
      • 2017-02-02
      • 2017-09-17
      • 2021-03-16
      相关资源
      最近更新 更多