【问题标题】:tsc doesn't detect Angular2 RC definitionstsc 未检测到 Angular2 RC 定义
【发布时间】:2016-10-25 23:14:51
【问题描述】:

我正在使用 angular 2.0.0-rc.1,但正在努力使用 typescript 编译器 (Typescript 1.8.10)。如果我在我的项目上运行 tsc,我会收到很多这样的错误:

app/app.component.ts(1,33): 错误 TS2307: 找不到模块 '@angular/core'

但是,我认为是因为 node_modules/@angular/core 中的package.json 有一行:

  "typings": "index.d.ts",

并且index.d.ts 提供了定义,这不应该是这样吗? VSCode 不会突出显示这些包的任何问题,如果我在导入中单击“转到定义”,它将链接到源代码。

我应该怎么做才能避免这样的编译器错误?

更新:

我的packages.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "sourceMap": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true
    },
    "exclude": [
        "node_modules",
        "platforms"
    ]
}

【问题讨论】:

  • 为什么不升级到 Angular 2 RC.3
  • @AngJobs 我正在开发 nativescript 运行时,对于 RC1 有更好的记录

标签: typescript angular tsc


【解决方案1】:

在您的 tsconfig.json 中排除 node_modules 文件夹

    {
      "compilerOptions": {

        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "module": "commonjs",
        "noEmitOnError": true,
        "noImplicitAny": false,

        "removeComments": false,
        "sourceMap": true,
        "target": "es6",
        "moduleResolution": "node",
        "suppressImplicitAnyIndexErrors": true,
        "watch":true
      },
      "compileOnSave": true,
      "exclude": [
        "node_modules",
        "typings/main",
        "typings/main.d.ts",

        "typings"
      ]
    }

【讨论】:

  • 请看我更新的问题,我已经排除了 node_modules,虽然我在你的回答中遗漏了一些其他选项,这些重要吗?
  • 是的,我认为你也应该排除这些。
猜你喜欢
  • 1970-01-01
  • 2016-12-05
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多