【问题标题】:TS2304: Cannot find name '__decorate' , '__metadata' and '__extends'TS2304:找不到名称“__decorate”、“__metadata”和“__extends”
【发布时间】:2017-12-30 15:38:24
【问题描述】:

我正在尝试为我的 Angular 应用程序集成 Karma 和 Jasmine,该应用程序目前位于 v4.1.3TypeScript@2.3.0 并使用 @types。这个问题不是其他TS2304 错误的重复,因为我没有遇到'require'或'process'等问题......

当我运行 npm test 时,在一堆组件文件中出现以下错误,

Cannot find name '__metadata'.
Cannot find name '__decorate'.
Cannot find name '__extends'.

tsconfig.json:

    {
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib" : ["es2015.core", "es6", "es7", "dom"],
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "sourceMap": true,
    "noEmitHelpers": true,
    "allowJs" : true,
    "types": [
      "hammerjs",
      "jasmine",
      "jquery",
      "lodash",
      "moment",
      "node"
  ],
    "typeRoots": [
      "node_modules/@types"
    ]
},
"exclude": [
"node_modules",
  "typings"
],

"awesomeTypescriptLoaderOptions": {
"resolveGlobs": true,
"forkChecker": true
},
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": { "rewriteTsconfig": false }
}

当我尝试搜索名称时,我在 .ts 文件中找不到它们。这个错误是从哪里产生的?它来自捆绑的js吗?

【问题讨论】:

  • 它仍然是重复的。没有被发现的东西的名称不同是无关紧要的。如果一个问题是关于添加两个名为 C 和 D 的整数变量,它仍然是关于如何添加 A 和 B 的同一个问题的重复;并没有因为变量名不同而不同。

标签: javascript angular typescript webpack typescript-typings


【解决方案1】:

这些函数是编译器助手。你有 "noEmitHelpers": true 禁用他们的世代导致错误。 TypeScript compiler options

【讨论】:

    猜你喜欢
    • 2019-04-21
    • 1970-01-01
    • 2022-01-20
    • 2017-08-11
    • 2017-08-23
    • 1970-01-01
    • 2017-11-03
    • 2019-12-24
    • 1970-01-01
    相关资源
    最近更新 更多